Angular directive, link is not called when attribute is updated

In the following example: http://plnkr.co/edit/OZjg6sUgl35GIriaabQg?p=preview

I have 2 directives, showCard inside inside ng-repeat, the link function is called anytime the attribute is updated. (see console)

Another showCards works correctly, but the link function is not called when the attribute is updated, but only once at the beginning.

I would like to understand the difference between these two types.

+6
source share
1 answer

The bind function is called only once for each element, so whenever you add a new card, the ngRepeat directive adds a new <show-card ...> that will call the link function.

If you want a function to be launched every time cards changed, you can add the $ watch function to the scope of the showCards function, for example:

  $scope.$watch('cards',function(){ console.log('multi',$scope.cards); },true); 
+9
source

All Articles