Angular2: Disable a formbuilder's element

爷,独闯天下 提交于 2019-12-11 01:08:31

问题


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]
  });
}

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.

Thanks!


回答1:


this.purchaseDataForm.get('price').disable() // .enable()

See also https://angular.io/docs/ts/latest/api/forms/index/AbstractControl-class.html#!#disable-anchor



来源:https://stackoverflow.com/questions/40792392/angular2-disable-a-formbuilders-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!