3
有誰知道我可以在Angular 2中測試這個屬性指令嗎?我正在尋找一些例子,但我還沒有找到它。如果有人有一個例子來展示我或者讓我有辦法做到這一點,它會幫助我。測試屬性指令
import { Directive, SimpleChanges, Input, OnChanges, ElementRef, Renderer} from '@angular/core';
@Directive({
selector: '[highlightData]'
})
export class HighlightDataDirective implements OnChanges {
private _highlightData: string;
@Input() set highlightData(value: string) {
const prev = this._highlightData;
this._highlightData = value;
const cur = value;
}
constructor(private _elementRef: ElementRef, private _render: Renderer) {
}
ngOnChanges(changes: SimpleChanges) {
if (changes['highlightData'] && !changes['highlightData'].isFirstChange()) {
const prev: string = changes['highlightData'].previousValue;
const cur: string = changes['highlightData'].currentValue;
if (cur !== prev) {
this._render.setElementClass(this._elementRef.nativeElement, 'animate', true);
setTimeout(() => {
this._render.setElementClass(this._elementRef.nativeElement, 'animate', false);
}, 3000);
}
}
}
}
謝謝。