简体   繁体   中英

Angular: one-time binding, recompiling of nested ng-repeat

I am using one-time binding and kcd-recompile , but have a problem with nested ng-repeat . Let's assume the code looks like this:

<div ng-repeat="person in ::people">
    <div ng-repeat="friend in ::person.friends" kcd-recompile="person.friends">
        {{friend.name}}
    </div>
</div>

If I add a friend to one of the people now, I want this person div to be recompiled without recompiling the other people's divs. The problem is: person.friends is only updated, if person is updated.

So it works if I add the kcd-recompile to the first ng-repeat , but then every person's div is recompiled (which I want to prevent).

Is there any possibility to update person without recompiling the whole first ng-repeat ?

Found a solution on my own (after hours), if anyone needs it:

Using people[$index].friends instead of person.friends , it works!

<div ng-repeat="person in ::people"> <div ng-repeat="friend in people[$index].friends" kcd-recompile="person.friends"> {{friend.name}} </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