I can't make the directive work in a lazy loaded module. I've read the documentation and I simply added the directive into declarations array of my main module. The directive works as expected at that module, but it doesn't work in lazy loaded modules. It even prevents lazy loaded module to be opened because of the template error:
Can't bind to 'myHighlight' since it isn't a known property of 'p'
Here's my Plunker.
Check out errors in console after clicking 'go to child'
That's because your directive is declared in
AppModule
and it's only available there. If you want to use directive in both modules, you can createSharedModule
and then declare and export directive from there, and then importSharedModule
in yourAppModule
and yourChildModule
:Now you just need to add
SharedModule
toAppModule
's andChildModule
's imports.Note:
You have to remove your directive from
AppModule
's declarations since it can only be declared once.