angularangular-module

What is the difference between declarations, providers, and import in NgModule?


I am trying to understand Angular (sometimes called Angular2+), then I came across @Module:

  1. Imports

  2. Declarations

  3. Providers

Following Angular Quick Start


Solution

  • Angular Concepts

    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).

    For more details about modules see also https://angular.io/docs/ts/latest/guide/ngmodule.html

    TypeScript (ES2015) imports

    import ... from 'foo/bar' (which may resolve to an index.ts) are for TypeScript imports. You need these whenever you use an identifier in a typescript file that is declared in another typescript file.

    Angular's @NgModule() imports and TypeScript import are entirely different concepts.

    See also jDriven - TypeScript and ES6 import syntax

    Most of them are actually plain ECMAScript 2015 (ES6) module syntax that TypeScript uses as well.