In the following example: http://plnkr.co/edit/OZjg6sUgl35GIriaabQg?p=preview
I've got 2 directives, the showCard
one inside an ng-repeat which link
function get called any time the attribute is updated. (see the console)
The other one showCards
is working properly but the link
function is not called when the attribute is updated, but only once at the beginning.
I'd like to understand the difference between those 2 kind.
The linking function is only invoked once per element, so whenever you add a new card the ngRepeat-directive will add a new <show-card ...>
which will invoke the link function.
If you want some function to trigger every time cards
is changed you can add a $watch function on the scope in the showCards link function, like this:
$scope.$watch('cards',function(){
console.log('multi',$scope.cards);
},true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With