有人可以提供一个简单的例子来演示实现装饰器的正确方法,并描述可能的有效装饰器签名中的参数是什么意思吗?
declare type ClassDecorator = <TFunction extends Function>(target: TFunction) => TFunction | void;
declare type PropertyDecorator = (target: Object, propertyKey: string | symbol) => void;
declare type MethodDecorator = <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void;
declare type ParameterDecorator = (target: Function, propertyKey: string | symbol, parameterIndex: number) => void;
Run Code Online (Sandbox Code Playgroud)
另外,在实现装饰器时是否应该记住哪些最佳实践注意事项?
我有一个指令,它是一个@Input
接受一个类.
@Directive({selector: 'my-directive'})
@View({directives: [CORE_DIRECTIVES]})
export class MyDirective {
@Input() inputSettings : SettingsClass;
@Input() count : number;
onChanges(map) {
console.log('onChanges');
}
}
Run Code Online (Sandbox Code Playgroud)
该指令用于html:
...
<my-directive [input-settings]="settings" [count]="settings.count"></my-directive>
...
Run Code Online (Sandbox Code Playgroud)
如果settings.count已更改,onChanges
则会触发.如果设置类中的任何其他属性发生更改,则不会触发.
如何检测设置中的任何属性是否有变化?