0

This is json like this -[{"1":"B"},{"2":"A"},{"100":"E"},{"104":"P"},{"105":"A"},{"1551":"D"}]

and want it to create an select tag which should be look like this

<select name="">
   <option value="1">B</option>
   <option value="2">A</option>
   <option value="100">E</option>
   ...
</select> 
Sachila Ranawaka
  • 39,756
  • 7
  • 56
  • 80
John Ambrose
  • 167
  • 1
  • 11
  • http://stackoverflow.com/questions/12139152/how-do-i-set-the-value-property-in-angularjs-ng-options#22997081 – aslavkin Feb 23 '17 at 11:04

1 Answers1

1

Try like this.

var app = angular.module("app",[]);

app.controller('MainCtrl', function($scope) {

  $scope.data = [{"1":"B"},{"5":"A"}];
  
  $scope.getData = function(){
     var d = {};
     angular.forEach($scope.data,function(value,key){
       for(var v in value){
        d[v] = value[v];
       }
    });
    return d;
  }
  
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="MainCtrl">
 <select ng-model="sel" ng-options="key as value for (key , value) in getData()"></select>
</div>
Hadi J
  • 16,989
  • 4
  • 36
  • 62