Angular2 Reactive Forms - Disable form control dynamically from condition

前端 未结 5 592
感情败类
感情败类 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条回答
  •  梦毁少年i
    2021-02-07 08:10

    you can use ternary operator here to disable form control conditionally.

    this.activityForm = this.formBuilder.group({
    docType: [{ value: '2', disabled: this.activeCategory != 'document' ? true : false }, Validators.required]
    });
    
    
    

提交回复
热议问题