javascript - AngularJS display list from an array -
i have controller returns array, i'm trying display every element of array list.
what attempting do, not working:
<li ng-repeat="name in names"> <a ng-controller="postsctrl" href="#">{{response.text}}</a> </li>
response.text returns array controller.
i wondering, value of ng-repeat attribute supposed be, unique string?
thank you!
define array in controller $scope variable:
app.controller('postsctrl', function($scope) { $scope.response = { text: ['hello', 'world'] }; }
then utilize ng-repeat on variable, not controller.
<div ng-controller="postsctrl"> <ul> <li ng-repeat="name in response.text"><a href="#">{{name}}</a></li> </ul> </div>
the controller used define $scope variables can utilize in section, , not used variable itself.
javascript arrays angularjs list angularjs-ng-repeat
No comments:
Post a Comment