Bug?
1) import Angular 2 material module in ROOT (main/app module) with MaterialModule.forRoot()
2) Use compoments in every module, which is imported in Main/App module
If i use Material components in another module, it wont find a known element
Just try to use NG2 material component in other module that main / app
Win 10 x64, Angular-CLI 22-1, Angular 2.2.3
Is it correct to rly provide only way to import NG2 module for root? Shall we just import Material module in out "Shared" module which is shared in every other module??
I think this strange behavior ( bug) could be because of changes in angular CLI in latest versions.. (Maybe the custom decorator are stripped?).
What is the correct usage of NG2 material if we have multiple Modules and we wish tu use NG2 material in each of them?
I made it work..
My shared module:
imports: [
MaterialModule.forRoot()
],
providers: [],
exports: [
MaterialModule
]
is it correctl way how to solve that?
@montella1507 yes, import MaterialModule in your shared module, which you then import in your other modules.
I do it this way and it works fine.
This is standard angular behavior.
And the forRoot should only be imported once; ideally in the root component.
I think that forRoot() will set/import services/providers for dependency injection, so maybe it should be imported like that in AppModule (root module)??
So what about importing in shared module WITHOUT forRoot() (import declarations),
and import it again in Root module WITH forRoot() than for providers?
MaterialModule.forRoot() only once in the root module.
Just MaterialModule in all other modules.
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
_This action has been performed automatically by a bot._
Most helpful comment
MaterialModule.forRoot()only once in the root module.Just
MaterialModulein all other modules.