Angular ionic 3:动态更改按钮颜色:数据绑定不起作用
我正在使用Ionic3,我正在尝试为按钮设置动态颜色,我惊讶地发现数据绑定存在问题: 关于.ts: home.html:Angular ionic 3:动态更改按钮颜色:数据绑定不起作用,angular,ionic-framework,Angular,Ionic Framework,我正在使用Ionic3,我正在尝试为按钮设置动态颜色,我惊讶地发现数据绑定存在问题: 关于.ts: home.html: 因此,当我按下标记时,按钮内容不会改变,但当我点击按钮时,markers.length会更新,实现会按预期进行。您应该使用Angular ngZone服务进行此操作。请在此处阅读更多信息: import { Component, ViewChild, ElementRef } from '@angular/core'; export class AboutPage {
因此,当我按下标记时,按钮内容不会改变,但当我点击按钮时,markers.length会更新,实现会按预期进行。您应该使用Angular ngZone服务进行此操作。请在此处阅读更多信息:
import { Component, ViewChild, ElementRef } from '@angular/core';
export class AboutPage {
markers:any[]=Array();
// many code between those two lines
test(){
alert(this.markers.length);
}
}
<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>
this.ngZone.run(() => {
this.markers.push(marker);
});