How to reach variable outside the ng-repeat scope

两盒软妹~` 提交于 2019-12-02 10:23:50

you can call a function while clicking the list inside ng-repeat like this

<a href="#" ng-click="setCount($index)">

and defining the function in controller

 $scope.setCount = function(index) {
    $scope.count = index;
} ;

and updating the count value when you click

Here is a working plunker with your code,

http://embed.plnkr.co/rAbanmAR2Chw3P501tDc/preview

Hope this helps!

You can create function in the controller to set the count or refer the parent scope from inside the ng-repeat

ng-click="$parent.count = $index"

using parent scope

using function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!