Is there a way in angular to get binding back from a template?
In other words, if I have something like this:
<div ng-repeat="item in list">
<div>{{item.name}}</div>
<div>{{item.state}}</div>
</div>
would it be possible to change the item’s state by clicking on it, because the repeated div would “remember” what item it was built from?
Yes, you can use the
ng-clickdirective to trigger a method on the current scope:Or you can simply set an expression such as
ng-click="item.state='whatever'"directly on the div, although this is less testable – only in end-to-end tests – and less flexible, say you want to introduce validation or something).HTH