Angular2 Reactive Forms - Disable form control dynamically from condition

前端 未结 5 602
感情败类
感情败类 2021-02-07 08:05

I have a select control that I want to disable dynamically based on a condition:

this.activityForm = this.formBuilder.group({
  docType: [{ value: \'2\', disable         


        
5条回答
  •  情歌与酒
    2021-02-07 08:11

    from .ts file you can add keys to yours from controls, and there you add the item disabled:true (desactivate form item) or false (activate form item)

    .ts

    public form_name=new FormGroup({
    
                  series: new FormControl({value: '', disabled: true}),
                  inten: new FormControl({value: '', disabled: true}),
                  rep: new FormControl({value: '', disabled: true}),
                  rest: new FormControl({value: '', disabled: false}),
                  observation: new FormControl({value: '', disabled: false}),
    
    
    
      });
    

    .html

提交回复
热议问题