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?

2
  • have you tried using `ng-options' like this Commented Jan 18, 2017 at 4:39
  • Consider using the ng-options directive. For more information, see AngularJS ng-options Directive API Reference. Commented Jan 18, 2017 at 4:40

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

6 Comments

@shilpa you are welcom
If i select particular bank in the list, How to link the dependble drop down, with one more API which i have for next drop down? can u please help..
yes sure! do you want to call another api and get data?
yes with dynamic drop down, I have one more API of states list based on selecting particular bank, should i use ui-routing?
no need touse routing for that, do you have to pass selected bank as a parameter for the new api?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.