ng-options – OnlineWebTutorial.Com

Select options – AngularJS

ng-options is used to create options list from select drop down. It traverses through array or object to make the options list. <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script> <div ng-app="firstApp" ng-controller="firstCtroller"> <select ng-model="stateDropdown" ng-options="y.state for y in addr"></select> </div> <script> var app = angular.module("firstApp", []); app.controller('firstCtroller', function($scope) { $scope.addr = [ {state:"Hyderabad",city:"sikandrabad"}, {state:"UP",city:"GZB"}, {state:"Delhi",city:"Anand vihar"}, {state:"Panjab",city:"Chandigrah"}, {state:"Hariyanana",city:"Sonipat"} ]; }); </script> Try Note: drop down selected values will be objects if select drop down is created using ng-options. While using ng-repeat, drop down values for selected ones are strings. For example: <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script> <div ng-app="firstApp" ng-controller="firstCtroller"> <select ng-model="stateDropdown"> <option ng-repeat="y in addr" value="{{y.state}}">{{y.state}}</option> </select> </div> […]


Facebook
Google+
Twitter
Visit Us
PINTEREST
LinkedIn