Angular 2 - Declared directives still have errors

In RootModule :

 @NgModule({ imports: [ ModuleA ], declarations: [ ScrollToWhen ], bootstrap: [BootComponent], }) class RootModule {} 

In one of the component templates inside module A, I use ScrollToWhen , but I got an error: Can't bind to 'scrollToWhen' since it isn't a known property of 'div' .

Why?

Error: Unexpected directive 'HbClass' imported by the module 'Module'

+5
source share
1 answer

Either add ScrollToWhen to ModuleA , or move it to a module, which you can then add to imports: [...] from ModuleA to make it available.

A component / directive can be specified in only one single module in declarations: [...] . Then import this module wherever you want to use this component / directive.

For the module used to declare directives and the channel, you need to install them in exports as:

 @NgModule({ declarations: [ myDirectives ], exports: [ myDirectives ] }) 
+9
source

All Articles