microchip78
microchip78

Reputation: 2060

declare Angular2 component at top level module and use at lower level modules

I am working on Angular2 application using Angular2 final release.

enter image description here

This is my application scenario. I have a component which I want to use same component at two different modules at two different level.

If I declare it at FeatureModule and use it it works. And I haven't tried but if I export it from FeatureModule then it would work in main module as well.

But component i designed is not feature specific. So it doesn't seem right to declare it at FeatureModule level and then propagate to other levels. I think it would be more appropriate to declare at AppModule level or MainModule level and use it in both MainModule & FeatureModule level. But this doesnt work. It is throwing following error.

If 'xxxx' is an Angular component, then verify that it is part of this module.

Any idea, how to achieve this?

Upvotes: 0

Views: 798

Answers (2)

DerekMT12
DerekMT12

Reputation: 1349

You can put your component in a separate module and have your Main and Feature modules import it.

Upvotes: 1

Yaroslav Grishajev
Yaroslav Grishajev

Reputation: 2137

I'd suggest to declare it on bootstrapping in AppModule. Then you could use it app wide.

Upvotes: 0

Related Questions