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

前端 未结 6 1046
面向向阳花
面向向阳花 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-02 04:00

    Components are declared, Modules are imported, and Services are provided. An example I'm working with:

    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule } from '@angular/core';
    
    
    import { AppComponent } from './app.component';
    import {FormsModule} from '@angular/forms';
    import { UserComponent } from './components/user/user.component';
    import { StateService } from './services/state.service';    
    
    @NgModule({
      declarations: [
        AppComponent,
        UserComponent
      ],
      imports: [
        BrowserModule,
        FormsModule
      ],
      providers: [ StateService ],
      bootstrap: [ AppComponent ]
    })
    export class AppModule { }
    

提交回复
热议问题