Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
171
rated 0 times [  172] [ 1]  / answers: 1 / hits: 58852  / 10 Years ago, mon, november 10, 2014, 12:00:00

I have a controller that returns an array, I'm trying to display every element of that array as a list.



What I am attempting to do, which is not working:



<li ng-repeat=Name in names>
<a ng-controller=PostsCtrl href=#>{{response.text}}</a>
</li>


response.text returns an array from the controller.



I am also wondering, what is the value of the ng-repeat attribute supposed to be, any unique string?



Thank you!


More From » arrays

 Answers
3

Define the array in your controller with the $scope variable:



app.controller('PostsCtrl', function($scope) {
$scope.response = { text: ['hello', 'world'] };
}


Then use ng-repeat on the VARIABLE, not the controller.



<div ng-controller=PostsCtrl>
<ul>
<li ng-repeat=name in response.text><a href=#>{{name}}</a></li>
</ul>
</div>


The controller is only used to define what $scope variables you can use in that section, and is not used as a variable itself.


[#68844] Friday, November 7, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
shylaelisan

Total Points: 37
Total Questions: 94
Total Answers: 110

Location: Angola
Member since Tue, May 5, 2020
4 Years ago
;