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

后端 未结 7 1453
孤街浪徒
孤街浪徒 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:49

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

    Did not work for me in Angular 8. So I made it work by adding a 'readonly' attribute inside the HTML and then change its value in .ts file.

    inside .html file

     
    

    inside .ts file

    email_readonly = false;
    
    yourFunction()
    {
      this.email_readonly = true;
    }
    

提交回复
热议问题