Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
57
rated 0 times [  62] [ 5]  / answers: 1 / hits: 13966  / 10 Years ago, mon, june 30, 2014, 12:00:00

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 .


More From » json

 Answers
6

I think that ng-options, because that is meant to be used in cases like this.



Angularjs Docs:-



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.


[#44231] Saturday, June 28, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
pranavrorys

Total Points: 466
Total Questions: 87
Total Answers: 115

Location: Barbados
Member since Sun, Nov 27, 2022
2 Years ago
pranavrorys questions
Fri, May 27, 22, 00:00, 2 Years ago
Thu, Oct 28, 21, 00:00, 3 Years ago
Sat, May 30, 20, 00:00, 4 Years ago
Fri, Dec 20, 19, 00:00, 5 Years ago
;