i have to display the JSON data in drop down list ,for that i have two options one of the options is By using ng-repeat and other one is ng-options.
ng-repeat code :
in html file :
<select>
<option ng-repeat="prod in testAccounts" value="{{prod.id}}">{{prod.name}}</option>
</select>
and in script file:
$http.get('document.json').success(function (data)
{
$scope.testAccounts = angular.fromJson(data);
}
and other one ng-options :
in html file :
<select ng-model="selectedTestAccount" ng-options="c as c.name for c in testAccounts1"></select>
in script file:
$http.get('document.json').success(function (data)
{
$scope.testAccounts1 = data;
$scope.selectedTestAccount = $scope.testAccounts1[0];
}
Now i want to know which one is best for my project to improve the performance .Any guidelines please .
I think that ng-options, because that is meant to be used in cases like this.
ngOptions provides an iterator facility for the element which should be used instead of ngRepeat when you want the select model to be bound to a non-string value. This is because an option element can only be bound to string values at present.