#custom structural directive - help

6 messages · Page 1 of 1 (latest)

broken atlas
#

Hello everyone, I'm new to Angular and I'm trying to create a custom structural directive that can listen to a router link element isActive and call a callback in case it's true. I've googled all day to find an example of what I'm trying to achieve with no luck. Can anyone please let me know if this is indeed possible?

ripe pebble
#

BTW, such a directive wouldn't be a structural one

broken atlas
#

I wanna use the output of the routerLinkActive directive to call a function from the parent component in case an element isActive is true. The problem is that I need to do this for dozens of elements, so I thought that a custom directive would be a more elegant solution. I was reading about host directives and how you can compose directives with it. In theory it sounds like what I should be doing but if I use RouterLinkActive as host directive in my custom one, I don't know how to access its isActive property.

ripe pebble
#

You inject it into your own directive.

broken atlas
#

Thanks, I added routerLinkActive to my directive constructor and can inspect the values in ngOnInit but I am trying to call a callback function inside no changes but nothing happens. How can I react to changes to isActive inside my custom directive?