Angular 6 how to make all input's Not editable element inside a form

后端 未结 7 1428
孤街浪徒
孤街浪徒 2021-02-19 18:15

Is there a way to disable and make all fields non editable (input / mat-select / textfield / option/input/mat-checkbox etc) inside a Form

7条回答
  •  离开以前
    2021-02-19 18:55

    If you are using reactive form you can achieve this programmatically like this (one-by-one approach):

     this.formGroupName.controls[controlNmae].disable();
    

    Eg: this.formGroupName.controls['lastName'].disable()

    To disable all at once:

    this.formGroupName.disable()
    

    In your case do: this.leaseholderForm.disable()
    And to turn it back do: this.leaseholderForm.enable()

    What you can do is create a function like this and call it after you have called createLeaseholderForm():

    disableForm() {
     this.leaseholderForm.disable()
    }  
    

    for more info read this.

提交回复
热议问题