1

I've managed to play with directive attribute listener without using isolated scope ($watch, $observe and $parse - a pleasure) but I experience difficulties understanding the last one.

Here's my html :

<div active="setActiveNav(number1)"></div>

And my directive :

link: function(scope,elem,attr){
    scope.myFunction = $parse(attr.active);
    ...
}

But can you explain how do I fire the function passed in my 'active' attribute ?

Snowcraft
  • 43
  • 4

1 Answers1

0

Check this answer for a complete answer to your question

As a sumary you have plenty of choices depending on how you want your directive to work

  • pass it to the directive directly scope: { active: "&active" }
  • $parse(attr.active)(scope))
  • scope.$eval(attr.active)
Community
  • 1
  • 1
dco
  • 317
  • 1
  • 13