第一部分:概览
declarations?: 属于这个模块的 component, pipe, directive 的列表。
providers?: Provider[]; 这个。。。
imports?: Array<Type<any> | ModuleWithProviders<{}> | any[]>;
exports?: Array<Type<any> | any[]>; 列出当前模块哪些 compnent,pipe,directive需要导出。
entryComponents?: Array<Type<any> | any[]>; 从v9.0.0启用ivy后,这个属性就不需要了。
bootstrap?: Array<Type<any> | any[]>; 没说一定要rootModule才能有这个。
schemas?: Array<SchemaMetadata | any[]>; elements 和 properties既不是组件也不是指令,只能在schema里面声明;
可选值:`NO_ERRORS_SCHEMA` and `CUSTOM_ELEMENTS_SCHEMA`
id?: string; 用于 getModuleFactory. 啥意思???
jit?: true; 如果写上,这个模块会被AOT编译器忽略。
第二部分:详解
providers
看这里:Angular: Provider_“加油吧,小白菜”的博客-CSDN博客
bootstrap
用于根模块启动根组件。
乱用会报错。
schemas
import { CUSTOM_ELEMENTS_SCHEMA,
NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
@NgModule({
schemas: [
CUSTOM_ELEMENTS_SCHEMA,
NO_ERRORS_SCHEMA
],
})
export class AppModule {}
1)、CUSTOM_ELEMENTS_SCHEMA:
Defines a schema that allows an NgModule to contain the following:
定义一个模式允许ngModule包含以下规则
- Non-Angular elements named with dash case (`-`).
非angular元素用破折号命名
- Element properties named with dash case (`-`).
元素属性用破折号命名
Dash case is the naming convention for custom elements.
破折号是自定义元素的命名约定。
2)、NO_ERRORS_SCHEMA:
Defines a schema that allows any property on any element.
定义一个模式,元素拥有任何属性
This schema allows you to ignore the errors related to any unknown elements or properties in a template. The usage of this schema is generally discouraged because it prevents useful validation and may hide real errors in your template. Consider using the `CUSTOM_ELEMENTS_SCHEMA` instead.
这个模式让你忽略模版上未知元素或属性的报错。不推荐使用这种用法,因为它阻碍了有用的检测并且可能隐藏你模版里面真正的错误。如果你有需要,推荐用CUSTOM_ELEMENTS_SCHEMA 代替。
id
假设已经有个一个模块HomeModule,具有属性id:'home', 并且已经被加载了(比如被import),那么可以用如下代码获取到这个模块:
import { getModuleFactory } from '@angular/core';
ngOnInit() {
let module = getModuleFactory('home');
console.log(module);
}
export declare const getModuleFactory: (id: string) => NgModuleFactory<any>;
具体用来干嘛,后面再补。
jit (运行时编译)
要么不写,如果写上取值只能是true。如果存在,则该指令/组件将被 AOT 编译器忽略。它会保留在发布代码中,并且 JIT 编译器会尝试在运行时在浏览器中对其进行编译。为了确保其行为正确,该应用程序必须导入 @angular/compiler
。
AOT: ahead of time , 提前编译。
应该没有需要 jit 的吧?
!!! jit不要乱写,写了这个属性,开发模式下跑不了。