运行ng test
时出现以下错误:
Can't bind to 'foobar' since it isn't a known property of 'app-my-item'.
1. If 'app-my-item' is an Angular component and it has 'foobar' input, then verify that it is part of this module.
2. If 'app-my-item' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
组件:
import { Component, Input, OnInit, Renderer, EventEmitter, Output, OnChanges, SimpleChanges } from '@angular/core';
@Component({
selector: 'app-my-item',
templateUrl: './app-item.component.html',
styleUrls: ['./app-item.component.scss'],
})
export class MyItemComponent implements OnInit, OnChanges {
@Input() video;
@Input() foobar = <string> '';
buttonClass = 'green';
// Code....
ngOnChanges({ foobar: { currentValue } }: SimpleChanges): void {
if (currentValue) {
this.buttonClass = (
currentValue === this.video.key ? 'blue' : 'green'
);
}
}
// Code....
}
查看:
<app-my-item
//Code ....
[foobar]="foobar"
//Code ....
>
</app-my-item>
我不明白为什么会收到错误消息,因为foobar
实际上是在组件中定义为输入的。如何解决此错误?