在文件 app.component.ts 第 1 行 import { Component } from 'angular/core'; 我一直无法在文件夹中找到 Component 的实现。
装饰器的实现Component
由两部分组成:
makeDecorator 函数- 这是实现主要功能的地方,特别是定义类的元数据:
const TypeDecorator: TypeDecorator = <TypeDecorator>function TypeDecorator(cls: Type<any>) {
const annotations = Reflect.getOwnMetadata('annotations', cls) || [];
annotations.push(annotationInstance);
Reflect.defineMetadata('annotations', annotations, cls);
return cls;
};
和组件装饰器属性,它定义了装饰器的默认属性Component
:
export const Component: ComponentDecorator = <ComponentDecorator>makeDecorator(
'Component', {
selector: undefined,
inputs: undefined,
outputs: undefined,
host: undefined,
exportAs: undefined,
moduleId: undefined,
providers: undefined,
viewProviders: undefined,
changeDetection: ChangeDetectionStrategy.Default,
...
您可能想阅读文章在 Angular 中实现自定义组件装饰器
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句