使用Ionic框架我正在尝试使用Angular创建可点击列表。
<ion-list>
<ion-item *ngFor="let device of devices">
<span *ngClick="showDevice(device)">
{{ device }}
</span>
</ion-item>
</ion-list>
错误报告是ngClick is not a property of span
。将span
更改为ng-template
只会给我同样的错误。把代码放在这个
<ion-list>
<ion-item *ngFor="let device of devices" *ngClick="showDevice(device)">
{{ device }}
</ion-item>
</ion-list>
它说cannot have multiple bindings on one attribute
。它还说回...verify it as part of this module
我没有意义。
知道如何将ngClick放入ngFor循环中吗?
答案 0 :(得分:3)
试试这个:
<ion-list>
<ion-item *ngFor="let device of devices">
<span (click)="showDevice(device)">
{{ device }}
</span>
</ion-item>
</ion-list>
或者这个:
<ion-list>
<ion-item *ngFor="let device of devices" (click)="showDevice(device)">
{{ device }}
</ion-item>
</ion-list>
答案 1 :(得分:2)
您可以使用(点击)代替* ngClick。它会看起来像这样。
<ion-list>
<ion-item *ngFor="let device of devices">
<div (click)="showDevice(device)">
{{ device }}
</div>
</ion-item>
</ion-list>
答案 2 :(得分:1)
ng-click是angular v1语法,你应该只使用 (click)
和angular
<ion-list>
<ion-item *ngFor="let device of devices" (click)="showDevice(device)">
{{ device }}
</ion-item>
</ion-list>