1

This is my HTML code

<body ng-app="mainApp">
    <div ng-controller="myController">
        <select>
<option ng-repeat="person in persons">{{ person.data }}</option>
</select>
    </div>
</body>

This is my JavaScript code

var app = angular.module("mainApp", []);
app.controller("myController", function($scope, $http) {
    $http.get("JSON URL")
        .success(function(response) {
            $scope.persons = response.data;
        });
});

My JSON URL is in this format [{"status": "success", "data": ["bank1","bank2","bank3"]}], I want only "data" list in drop down, there is too many banks in JSON data, How to use select and option?

shilpa
  • 159
  • 1
  • 1
  • 12
  • have you tried using `ng-options' like [this](http://stackoverflow.com/questions/13047923/working-with-select-using-angulars-ng-options) – logee Jan 18 '17 at 04:39
  • Consider using the `ng-options` directive. For more information, see [AngularJS ng-options Directive API Reference](https://docs.angularjs.org/api/ng/directive/ngOptions). – georgeawg Jan 18 '17 at 04:40

1 Answers1

0

You can do this,

Controller:

app.controller("dobController", ["$scope", "$http",
  function($scope, $http) {
    $http.get("test.json").then(function(response) {
      $scope.data = response.data[0].data;
      console.log($scope.data);
    })
  }

]);

HTML:

<body ng-controller="dobController">
  <select class="form-control" id="selection" ng-model="currentSelected" ng-options="selection as selection for selection in data"></select>
</body>

DEMO

Sajeetharan
  • 216,225
  • 63
  • 350
  • 396