NgModule中import、declarations、providers的区别
文章目录
- imports makes the exported declarations of other modules available in the current module
- declarations are to make directives (including components and pipes) from the current module available to other directives in the current module. Selectors of directives, components or pipes are only matched against the HTML if they are declared or imported.
- providers are to make services and values known to DI (dependency injection). They are added to the root scope and they are injected to other services or directives that have them as dependency.
A special case for providers
are lazy loaded modules that get their own child injector. providers
of a lazy loaded module are only provided to this lazy loaded module by default (not the whole application as it is with other modules).
文章作者 p3p3pp3
上次更新 2019-04-04