【发布时间】:2019-03-20 14:40:48
【问题描述】:
我正在开发一个离子项目,并且在我的项目中,当我单击 1 个按钮时,其他按钮也会更改它们的值,因为它们具有相同的事件。但我想要相反,点击一个按钮应该只改变一个特定按钮的值。
HTML<table class="student_list">
<tr><ion-item *ngFor="let record of data">
<ion-avatar slot="start">
<img src="assets/student.png">
</ion-avatar>
<ion-label class="text2">{{record.name}} {{record.id}}
<span class="button1"><button (click)="toggleBackgroundColor()" ion-button [style.background-color]="hexColor" class="btn">{{text}}</button></span>
</ion-label>
</ion-item></tr>
</table>
TS 文件
public toggleBackgroundColor(): void {
if(this.hexColor === '#1e90ff') {
this.hexColor = '#ff0000'
this.text='A';
} else {
this.hexColor = '#1e90ff';
this.text = 'P'
} }
【问题讨论】:
-
如果您将相同的变量绑定到 2 个不同的按钮,则一个按钮的任何更改都将反映在这两个按钮上。您可以为不同的按钮使用不同的变量
标签: angular ionic-framework angular7 ionic4