禁用变量比实际值落后一步



我认为ionic angular最新更新中存在问题,因为相同的代码在以前的版本中运行良好。

<ion-button [disabled]="currentState === -1" (click)="changeState('undo')" fill="clear">
<ion-icon size="large" name="arrow-undo" slot="start"></ion-icon>
</ion-button>

我正在制作一个草图应用程序,当currentState === -1时,撤消按钮被禁用。当我画东西的时候,我把currenState的值增加+1。但问题是,当currenState === 0时按钮仍然被禁用,而当currenState === 1时按钮被启用。这意味着处于禁用状态的变量比实际值落后一步。为什么会发生这种情况?我还安慰了currentState的值,它在代码中没有改变。

试试这个

<ion-button [disabled]="currentState === -1 ? true : false" (click)="changeState('undo')" fill="clear">
<ion-icon size="large" name="arrow-undo" slot="start"></ion-icon>
</ion-button>

最新更新