简体   繁体   中英

Difference between 2 imports in Angular

I am an Angular beginner and I don't understand one point. In following code, there are 2 imports for BrowserModule . One is at the second line and another is in the @ngmodule . So what is the difference between them and each roles?

import { NgModule }      from '@angular/core';
**import { BrowserModule } from '@angular/platform-browser';**
import { AppComponent }  from './app.component';

@NgModule({
  **imports:      [ BrowserModule ],**
  declarations: [ AppComponent ],
  bootstrap:    [ AppComponent ]
})
export class AppModule { }

The first is the ES6 import, this has nothing to do with Angular specifically. It just means "We need BrowserModule from the @angular/platform-browser package.

The second (passed into NgModule ) is Angular specific. This one tells Angular that the AppModule will be using the tools declared in BrowserModule .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM