本文介绍了Angular2:禁用表单构建器的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在声明之后禁用我的表单构建器的一个元素,因为一旦我的视图被加载,我必须验证一些东西,所以这是我的 formBuilder 声明.
I'm trying to disable an element of my formbuilder after the declaration because I have to validate something once my view is loaded, so this is my formBuilder declaration.
ionViewDidLoad() {
this.purchaseDataForm = this.formBuilder.group({
kms: ['', Validators.required],
lts: ['', Validators.required],
price: ['', Validators.required],
total: ['', Validators.required]
});
}
我不知道该怎么做,因为我想在完成本地验证后禁用 total
元素.我希望你能帮助我.
I have no idea how to do that because I want to disable the total
element once finished my local validation. I hope you can help me.
谢谢!
推荐答案
this.purchaseDataForm.get('price').disable() // .enable()
另见https://angular.io/docs/ts/latest/api/forms/index/AbstractControl-class.html#!#disable-anchor
这篇关于Angular2:禁用表单构建器的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!