为什么Angular在app.modules.ts中导出空类? [英] Why Angular export empty class in app.modules.ts?
问题描述
我是Angular的新手,正在使用Angular 4,并且通过ng new
命令使用Angular CLI创建了一个应用程序.
I am new in Angular, I am using Angular 4, and I made an app using the Angular CLI, by ng new
command.
在main.ts中,我们有
In main.ts, we have
...
import {AppModule} from './app/app.module';
.
.
platformBrowserDynamic().bootstrapModule(AppModule);
和AppModule在app/app.module
中定义(如您所见),这是我们在app.module.ts
中拥有的内容:
and AppModule is defined (as you see) in app/app.module
, here is what we have in app.module.ts
:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
如您所见,它显示为export class AppModule { }
,它也用在platformBrowserDynamic().bootstrapModule(AppModule);
As you see it says export class AppModule { }
, and it also used in platformBrowserDynamic().bootstrapModule(AppModule);
有人可以帮我解释一下吗?
Can someone please explain this for me?
推荐答案
该类的主体确实为空.但是类(@NgModule
)上方的装饰器正在为该类提供其功能.因此,实际上,该类并不为空.在将装饰器应用到它之后,它不需要任何额外的逻辑. bootstrapModule
将一个类作为输入,并假定该类已用@NgModule
装饰,并以与您所拥有的类似的方式(声明,导入,提供者等)进行装饰.
The body of the class is indeed empty. But that decorator above the class (@NgModule
) is giving that class its functionality. So really, that class isn't empty. It just doesn't require any extra logic after the decorator is applied to it. bootstrapModule
takes a class as input and assumes that that class is decorated with @NgModule
configured in a manner similar to what you have (declarations, imports, providers, etc.).
这篇关于为什么Angular在app.modules.ts中导出空类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!