Home Will ng-repeat bind my custom directive DOM elements when they get reloaded?
Reply: 1

Will ng-repeat bind my custom directive DOM elements when they get reloaded?

cool breeze
1#
cool breeze Published in 2018-02-13 20:34:38Z

I have a ng-repeat that lists users and uses a custom directive.

My custom directive has some event handlers like click handlers etc.

This vm.UserList will get modified every time a drop down list value is changed in the UI. My question is, will the event handlers get updated whenever the UserList is modified by a drop down list?

The dropdownlist on change will make a remote API request and then set the JSON result of the users to the value of the UserList.

<div ng-repeat="u in vm.UserList">
    <div><div my-custom-directive user-id="{u.id}" >{u.email}</div></div>
    </div>
</div>      
Arashsoft
2#
Arashsoft Reply to 2018-02-13 21:47:47Z

Yes, it does. According to angularjs documentation:

ngRepeat uses $watchCollection to detect changes in the collection. When a change happens, ngRepeat then makes the corresponding changes to the DOM:

1- When an item is added, a new instance of the template is added to the DOM.

2-When an item is removed, its template instance is removed from the DOM.

3-When items are reordered, their respective templates are reordered in the DOM.

So your directive gets added to the page including all of the event handlers.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.390715 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO