How to reach variable outside the ng-repeat scope

前端 未结 2 1596
慢半拍i
慢半拍i 2021-01-26 12:18

Is possible to reach variable outside the ng-repeat scope?

jsfiddle: http://jsfiddle.net/zcbhubrw/

Here is the code:

HTML



        
相关标签:
2条回答
  • 2021-01-26 12:40

    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!

    0 讨论(0)
  • 2021-01-26 12:49

    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

    0 讨论(0)
提交回复
热议问题