javascript - Angular 中的更改不会禁用按钮

标签 javascript angular

我有这个按钮,每次表单无效时该按钮都会被禁用

<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/

相关文章:

javascript - FaceBook 登录按钮错误 : FB. 在调用 FB.init() 之前调用了 login()

javascript - 基于一周内毫秒数的舍入算法

angular - 在 Angular 中创建新日期时删除时区信息

typescript - Angular 2 + Ionic 2 + Barcode Scanner DOM 不更新绑定(bind)更改

Angular ngFor 生命周期

JavaScript:如何将网站结构的状态保存到链接(或哈希链接)

javascript - 转换为 mp3 完成后如何解决此 promise ( Fluent-ffmpeg )

javascript - 不使用 jquery Datepicker 选择日期范围

angular - 无法绑定(bind)到 'ngModelOptions',因为它不是 Angular 子模块中 'input' 的已知属性

javascript - Rxjs : understanding expand operator