[英]use of class in NgModule in Angular
What is the use of the class in NgModule in Angular? 在Angular中NgModule中的类有什么用? In @Component, the class can contain variables of the component.
在@Component中,类可以包含组件的变量。 What useful information could the class in NgModule contain?
NgModule中的类可以包含哪些有用的信息?
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Your class decorated with @NgModule will be empty, it is a class just to be exported to main.ts (probably), to bootstrap your application. 用@NgModule修饰的类将为空,它是一个类,只是要导出到main.ts(可能),以引导您的应用程序。
And others Modules are exported as classes so they can be imported into your root module. 其他模块作为类导出,因此可以将它们导入到根模块中。
I use module class constructor for some configuration initialization: 我使用模块类构造函数进行一些配置初始化:
@NgModule({...})
export class RecordEditorViewComponentModule {
constructor(private viewComponent: ViewComponent) {
viewComponent.registerComponent({
You can also use module methods to register the same module with different set of providers so several instances of a module will be instantiated. 您还可以使用模块方法向不同的提供程序集注册相同的模块,以便实例化模块的多个实例。 For example, the way routing module does that.
例如,路由模块的方式。 Router module provides two distinct methods to register module -
forRoot
and forChild
. 路由器模块提供两种不同的方法来注册模块 -
forRoot
和forChild
。 They both register the same module but with different set of providers. 它们都注册相同的模块,但具有不同的提供者集。 See this answer for more details.
有关详细信息,请参阅此答案 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.