shilpa
shilpa

Reputation: 159

Get JSON data in drop down list using AngularJS.js?

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?

Upvotes: 1

Views: 1335

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222702

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

Upvotes: 0

Related Questions