问题描述
我正在将Angular8与Reactive表单一起使用。最初,我将禁用“提交”按钮,直到整个表单中都填入有效数据为止。
<div>
<form>
...........
</for>
<button [disabled]="(checkifSaveEnabled() && !formCreateNewPlan.valid)"
(click)="createNewPlan()">Save</button>
</div>
在班级(TS)文件中:
checkifSaveEnabled() {
if (this.formCreateNewPlan.pristine || !this.formCreateNewPlan.valid) {
return true;
}
return false;
}
createNewPlan(): void {
this.submitted = true;
this.myservice.create(this.formCreateNewPlan.value).subscribe(result => {
if (result.success && result.data.planId > 0) {
...
}
}
这里一切都很好。但是,如果我从服务(API)响应中收到任何错误,我想禁用“提交时按下按钮”(以避免多次单击)并将其启用。如何实现呢?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)