我有这个按钮,每次表单无效时该按钮都会被禁用
<button [disabled]="createForm.invalid" type="submit" class="btn btn-primary pull-right button-spinner" tabindex="0" ><span>NEXT</span></button>
但似乎验证仅在每次我在表单控件上模糊而不是在更改时生效。
我还在 ngOnit 上添加了这个并更改了 [disabled]="isNextDisabled"
但似乎状态也会随着更改而改变
this.createForm.valueChanges
.subscribe(formValue => {
this.isNextDisabled = !this.createForm.valid;
}
);
表单的初始化:
this.createForm = this.formBuilder.group({
formText: ['', Validators.required],
list: ['', Validators.required]
)};
最佳答案
<!-- disable the button -->
<button>
Disable Button
</button>
<!-- enable the button -->
<button>
Enable Button
</button>
<!-- the target button -->
<button disabled="disabled">
I've been clicked {{count}} times.
</button>
follow the link below for getting the detail:
https://blogs.msdn.microsoft.com/laurieatkinson/2016/09/12/using-data-binding-with-angular-2-to-disable-a-button/
关于javascript - Angular 中的更改不会禁用按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58534266/