Angular 2 + Jasmine中的测试指令我收到错误

时间:2017-06-09 16:51:30

标签: angular unit-testing angularjs-directive jasmine

当我使用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);
      }
    }
  }

}

感谢。

0 个答案:

没有答案