[英]Why dont we add 'ngModule' in decorator array of app.module.ts
I am making an angular project and have made required components and imported modules too. 我正在做一个有角度的项目,并已经制作了所需的组件和导入的模块。 The main issue I see here ... is that we make 2 steps:
我在这里看到的主要问题是……我们分两个步骤:
There is an exception. 有一个例外。 Now, I expected that just like ' browser-module ' (pre-fetched) or 'forms-module' (added manually) -- in the step-2 (ie, decorator array) there should be an injection or name-addition for ' ng-Module '.
现在,我希望就像“ 浏览器模块 ”(预提取)或“表单模块”(手动添加)一样,在步骤2(即装饰器数组)中,应该为' ng-Module '。 Why is it not there?
为什么不在那里? Is this only exception or there is some other too?
这是唯一的例外,还是还有其他例外? Shouldn't 'ngModule' be added in decorator would have been a consistent way?
不应该在装饰器中添加“ ngModule”是一致的方式吗?
Note: Code is not required as app it is working fine.
注意:不需要代码,因为它可以正常工作。 The question is simple that if we are using a particular rule for all -- Components, Services, Modules, Pipes, Models and Interface -- why not for 'ngModule'?
问题很简单,如果我们对所有组件,服务,模块,管道,模型和接口都使用特定规则,为什么不对“ ngModule”使用?
NgModule is a class marked by the @NgModule decorator. NgModule是由@NgModule装饰器标记的类。 It is not a separate Module that is configured in your application.
它不是在应用程序中配置的单独模块。
It is required because you use @NgModule
decorator at definition of your module. 这是必需的,因为在模块定义时使用
@NgModule
装饰器。 It's just a decorator and not a module. 它只是一个装饰器,而不是一个模块。 You need to import its script because you simply use it.
您需要导入其脚本,因为只需使用它即可。 You can think of it as
@Input
or @Output
decorators. 您可以将其视为
@Input
或@Output
装饰器。 You import them within your components just to use it within component. 您将它们导入到组件中只是为了在组件中使用它。
You can look at the code of NgModule
您可以看一下
NgModule
的代码
It is an interface 这是一个接口
export interface NgModule { ...
However, BrowserModule
is a module that decorates itself with @NgModule
但是,
BrowserModule
是使用@NgModule
装饰自身的模块
@NgModule({providers: BROWSER_MODULE_PROVIDERS, exports: [CommonModule, ApplicationModule]})
export class BrowserModule { ...
AOT Complier contains 2 phases. AOT编译器包含2个阶段。
During Code Analysis Phase, with the help @ngModule class decorator AOT Compiler will get the metadata about the module. 在代码分析阶段,借助@ngModule类装饰器,AOT编译器将获取有关模块的元数据。 Using these details, it will create metadata.json for Compilation.
使用这些详细信息,它将为编译创建metadata.json。
During Code Generation Phase, it will create module factories. 在代码生成阶段,它将创建模块工厂。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.