相关疑难解决方法(0)

如何实现打字稿装饰器?

TypeScript 1.5现在有装饰器.

有人可以提供一个简单的例子来演示实现装饰器的正确方法,并描述可能的有效装饰器签名中的参数是什么意思吗?

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)

另外,在实现装饰器时是否应该记住哪些最佳实践注意事项?

decorator typescript

198
推荐指数
3
解决办法
7万
查看次数

在angular2中,如何在为@Input发送的对象上更改属性的onChanges

我有一个指令,它是一个@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则会触发.如果设置类中的任何其他属性发生更改,则不会触发.

如何检测设置中的任何属性是否有变化?

angular

37
推荐指数
1
解决办法
4万
查看次数

标签 统计

angular ×1

decorator ×1

typescript ×1