angular2 will not disable input based on true or false condition

前端 未结 4 2061
孤城傲影
孤城傲影 2021-01-04 18:39

I have a input box based on the below:

If a change a radio I see that the value changes to true for false:

 {{model_parameters_general.est         


        
相关标签:
4条回答
  • 2021-01-04 19:02

    It seems in rc.6 they have removed the ability to disable inputs dynamically on a template binding when using reactive forms. You have to monitor changes and call .disable() on the formControl you wish to disable now. I rather prefer the old way of doing things and hope that they bring it back or an equally useful solution.

    Chime in on this related github issue.

    0 讨论(0)
  • 2021-01-04 19:08

    Try using attr.disabled, instead of disabled

    <input [attr.disabled]="disabled?'':null"/>

    StackOverflow Answer

    0 讨论(0)
  • 2021-01-04 19:08

    For boolean properties you need to set them to null to get them removed

    <input [disabled]="model_parameters_general.estimationmethod=='ew' ? true : null" [(ngModel)]="model_parameters_general.lambda" 
      formControlName="lambda" type="text" class="form-control">
    
    0 讨论(0)
  • 2021-01-04 19:08

    Try following code.

    setControl(name: any, Isenable: boolean): void {
        let ctrl = this.checkInForm.controls[name];
        console.log(ctrl);
        Isenable ? ctrl.enable() : ctrl.disable();
    }
    

    Calling Statement

    this.setControl('ctrl name', true);    // enbale it
      this.setControl('ctrl name', false);    // disable it
    

    Thanks Happy Coding!

    0 讨论(0)
提交回复
热议问题