我正在为组件编写单元测试。它应该是一个弹出组件。我的想法是给它注入一个元素,使其弹出。 我在哪里做错了?
无法绑定到“ forEl”,因为它不是“ ctr-info-popup”的已知属性。
@Component({
template: `
<div #forEl class="bla" (click)="onMouseOver($event)"></div>
<ctr-info-popup [forEl]="context.forEl" [(show)]="context.show">
<div class="penalty-container">
<span class="penalty-title" [ngClass]="{'no-changes': !context.canChange}">{{context.title}}</span>
<span class="penalty" *ngFor="let penalty of context.penalties">{{penalty}}</span>
</div>
</ctr-info-popup>
`
})
class TestHostComponent{
context = null;
@ViewChild('forEl', {read: ElementRef}) forEl: ElementRef<HTMLDivElement>;
onMouseOver(event) {
this.context = {
forEl: this.forEl,
show: true,
canChange: false,
title: 'Test title',
penalties: ['p1', 'p2']
}
}
}