Directive after updating ngRepeat

I had a problem with AngularJS disabling the directive when ng-repeat completed the update. I have three named arrays that switch over three links, allowing me to display the selected array using ng-repeat. I would like to disable some code when it is finished, as I plan to set some element attributes for using D3.

I tried to check the scope. $ last is in my directive, but this is not called at the end of every ng-repeat process. If some data remains unchanged, it may not set the scope. $ Last to true.

http://plnkr.co/edit/hwmOlI6YrgS4H1C1h7k2?p=preview

So what is the best way to run code in a directive when ng-repeat is complete?

+4
source share
1 answer

Here is the solution. Note that the last triggers every time now.

http://plnkr.co/edit/xV1quqzorzxliS2shrP4?p=preview

You just need the $watch variable $ last , and it will work fine. This helps in situations where scope not created, but simply updated with new values. Your directive is created once, and if one of the repeating variables just changes the ng-repeat values, it optimizes and simply updates the values ​​(as opposed to deleting all values ​​and re-creating new ones). In this case, $scope.$last will be the updated variable, not what gets created. So you need $watch it.

+10
source

All Articles