简体   繁体   中英

Alias for $last in nested ng-repeat always returns true

I have two nested ng-repeat and need to rename $last for something like outerLast and innerLast. I'm doint it using ng-init="outerLast= $last" and ng-init="innerLast= $last", but it's not working. Both variables are always true. I guess it's cause $last will change from true to false in the last child scope create by the previous iteration as soon as the new iteration creates a new child scope and probably ng-init is not creating a bind between the new variable and $last.

How can I implement the expected behavior for outerLast and innerLast variables?

In the nested loop, use $parent to access the outer scope. So to access the $last variable, you must use $parent.$last .

Hopefully this helps you visualize how to reference $parent.last

<div ng-repeat="items in GroupOfItems">
  <div ng-repeat="item in items">
    outerLAST: {{$parent.$last}}
    innerLAST: {{$last}}
  </div>
</div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM