当我使用Angular 2 + Jasmine运行测试时,我收到以下错误。有谁知道如何解决这个问题?
我已经在app.module.ts中导入了该指令。
Can't bind to 'highlightData' since it isn't a known property of 'li'. ("[ERROR ->][highlightData]="item.name">
list.component.ts
<ul>
<li *ngFor="let item of list" [highlightData]="item.name">{{item.name}}</li>
</ul>
高亮data.directive.ts
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);
}
}
}
}
感谢。