jmbmage
jmbmage

Reputation: 2547

Angular: how to scope a function call to directive instead of controller?

<my-dir ng-show="isVisible()"></my-dir>

isVisible will call isVisible in the controller.

What if I want it to call isVisible inside the my-dir directive instead?

Note: my-dir in my application is a tree control that recursively calls itself using $compile so there may be many of them nested inside each other. Using a singleton service may not work because of asynchronicity.

EDIT: in retrospect I the correct answer was to create a filter for my directive. What can I say, Angular is a different way of doing things.

Upvotes: 1

Views: 54

Answers (1)

dave walker
dave walker

Reputation: 3108

If you're using a directive you have full control of the element. Just do this: <my-dir check-visible="true"></my-dir>

Then in the directive's link function you can just go: if(attrs.checkVisible) isVisible();

Then you can show or hide the element however you like.

Upvotes: 2

Related Questions