javascript - Displaying JSON data in drop-down in AngularJS -


my document.json file contains data like

[     {"name" :"b"},     {"name" :"a"},     {"name" :"d"},     {"name" :"e"} ] 

when try display json data in drop-down list, last element e displayed in drop down .my html file

<select ng-model="selectedtestaccount" ng-options="c c.name c in testaccounts"></select> 

and script file

sampleapp.controller('democtrl', function ($scope, $http) {   $scope.selectedtestaccount = null;   $scope.testaccounts = [];    $http.get('document.json').success(function (data) {     $scope.testaccounts = data;   }); }); 

how can display document.json data in drop-down list default selected first element in angularjs. guidelines please

your json isn't quite right. need have braces around each item, this:

[    { "name" :"b" },    { "name" :"a" },    { "name" :"d" },    { "name" :"e" }  ] 

you can select first item in dropdown default this:

$scope.selectedtestaccount = $scope.testaccounts[0]; 

demo


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -