【发布时间】:2018-03-26 23:27:43
【问题描述】:
我正在使用 Ionic3,我正在尝试为按钮设置动态颜色,但我惊讶地发现数据绑定存在问题:
关于.ts:
import { Component, ViewChild, ElementRef } from '@angular/core';
export class AboutPage {
markers:any[]=Array();
// many code between those two lines
test(){
alert(this.markers.length);
}
}
home.html:
<ion-content>
<ion-fab >
<button ion-fab color="light" (click)="test()" mini [color]="markers.length > 0 ? 'primary' : 'danger'">
{{markers.length}}
</button>
</ion-fab>
</ion-content>
因此,当我按下标记时,按钮内容不会改变,但是当我单击按钮时,markers.length 会更新并且实现按预期工作。
【问题讨论】: