Angular 2 ng module imports

2020-03-26 08:11发布

问题:

What is the significance of imports metadata of ngmodule decorator, when we are importing files at top. Difference between both the inputs.

回答1:

These imports are entirely different concepts.

The imports at the top of the file are TypeScript imports to make classes, interfaces and variables known to the current file and are not related to Angular2.

The @NgModule() imports are to make exports: [] of the imported @NgModule()s known to the importing @NgModule() so that they applied to components of the importing module if selectors match.

Also providers: [] of an imported module are added to the root scope of the injector (only when the module is not lazy loaded).