我的其中一个模板中包含以下代码:
<ion-col text-center *ngFor="let shape of data.items[0].expandItems | slice:0:4; let i=index">
<a #btn{{shape.value}} class="item item-text-wrap notselected" (click)="toggleButtonShape(shape)">
<img src="{{shape.url}}">
<p>{{shape.title}}</p>
</a>
</ion-col>
对应的.ts文件中的代码是:
toggleButtonShape(shape) {
shape.isChecked = !shape.isChecked;
if(shape.value === 'BR') {
if (shape.isChecked === true) {
this.removeClass('notselected', this.btnBR);
} else {
this.addClass('notselected', this.btnBR);
}
} }
addClass(className?: string, element?: any) {
this.renderer.addClass(element.nativeElement, className);
}
removeClass(className?: string, element?: any) {
this.renderer.removeClass(element.nativeElement, className);
}
问题是,当执行上述任何一个函数时,element参数为 undefined 。我已经声明了所有@ViewChilds()。