Angular2和禁用按钮异常 [英] Angular2 and disabling button exception

查看:87
本文介绍了Angular2和禁用按钮异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的代码中,我有一个按钮,该按钮在表单无效或不脏时会被禁用.

In my code I have button, that is disabled whenever the form is invalid, or not dirty.

我有:

<button type="submit" [disabled]="!myForm.valid || myForm.dirty" class="save-button">Save</button>

哪个丢给我了

例外:表达式'!myForm.valid ||检查后,MyFromComponent @ 58:38'中的myForm.dirty)已更改.先前的值:"true".当前值:[!myForm.valid ||中的'false' MyFromComponent @ 58:38中的myForm.dirty]

EXCEPTION: Expression '!myForm.valid || myForm.dirty) in MyFromComponent@58:38' has changed after it was checked. Previous value: 'true'. Current value: 'false' in [!myForm.valid || myForm.dirty in MyFromComponent@58:38]

每当有效性/肮脏度发生变化时.

Whenever the validity/dirty changes.

有什么想法吗?

更新

启用生产模式后,它会起作用:

It works when I enable production mode:

enableProdMode()

推荐答案

我认为这也将达到目的.

I think this will serve the purpose as well.

[disabled]="!myForm.valid || !myForm.dirty"

这篇关于Angular2和禁用按钮异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆