Enable When Checkbox is Check in Reactive Forms

前端 未结 2 507
太阳男子
太阳男子 2020-12-12 02:46

I need help in making the rows enable only when the checkbox is check. The default rows should be disabled but when the checkbox is only check, that row will be enabled. Her

2条回答
  •  伪装坚强ぢ
    2020-12-12 03:00

    Another aproach is create a directive

    @Directive({
      selector: '[enabledControl]'
    })
    export class EnabledControlDirective {
    
        @Input() set enabledControl(condition: boolean) {
            if (this.ngControl) {
                if (this.ngControl.control) {
                    if (condition)
                        this.ngControl.control.enable();
                    else
                        this.ngControl.control.disable();
                }
            }
      }
      constructor(private ngControl : NgControl ) {
      }
    }
    

    Then you can use like

    
    

提交回复
热议问题