When we import BrowserModule in root module of application ,we can use NgIf and NgFor( in eagerly loaded component). But for lazy loaded modules I have to import CommonModule which has been exported by BrowserModule of root. SO why do we have to import it again in lazy loaded module?
Angular – why lazy loaded module has to import commonModule? Angular 2
angularlazy-loading
Best Answer
As Ward Bell said(https://devchat.tv/adv-in-angular/119-aia-avoiding-common-pitfalls-in-angular2):
Modules don't inherit access to the components, directives, or pipes that are declared in other modules. (https://angular.io/guide/ngmodule#add-the-contactmodule see orange block)
That's why you have to import
CommonModule
to have access tongIf
,ngFor
and so on directives. Your module doesn't know anything about directives from other modules. It only looks at itsdeclarations
andexports
from imported modulesSee also: