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

前端 未结 6 1033
面向向阳花
面向向阳花 2020-12-02 03:39

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

  1. Imports

  2. Declarations

  3. <
6条回答
  •  执笔经年
    2020-12-02 03:54

    1. declarations: This property tells about the Components, Directives and Pipes that belong to this module.
    2. exports: The subset of declarations that should be visible and usable in the component templates of other NgModules.
    3. imports: Other modules whose exported classes are needed by component templates declared in this NgModule.
    4. providers: Creators of services that this NgModule contributes to the global collection of services; they become accessible in all parts of the app. (You can also specify providers at the component level, which is often preferred.)
    5. bootstrap: The main application view, called the root component, which hosts all other app views. Only the root NgModule should set the bootstrap property.

提交回复
热议问题