简体   繁体   English

Angular中2个导入的区别

[英]Difference between 2 imports in Angular

I am an Angular beginner and I don't understand one point. 我是Angular初学者,我不明白一点。 In following code, there are 2 imports for BrowserModule . 在以下代码中, BrowserModule有2个导入。 One is at the second line and another is in the @ngmodule . 一个在第二行,另一个在@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. 第一个是ES6导入,这与Angular没有任何关系。 It just means "We need BrowserModule from the @angular/platform-browser package. 它只是意味着“我们需要来自@angular/platform-browser软件包的BrowserModule

The second (passed into NgModule ) is Angular specific. 第二个(传入NgModule Angular特有的。 This one tells Angular that the AppModule will be using the tools declared in BrowserModule . 这个告诉Angular AppModule将使用BrowserModule声明的工具。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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