jeudi 1 octobre 2020

How to disable matInput until checkbox is checked

I've googled all I could for the solution for this, but none of them work. Not sure what is missing from my current method.

.html

            <div *ngFor="let table of xTables; let i = index;">
              <mat-checkbox formControlName="" [checked]="enableInput" (change)="enableInput = !enableInput"></mat-checkbox>
            </div>
            <mat-form-field>
              <input matInput formControlName="xType" placeholder="X Type" [attr.disabled]="!enableInput">
            </mat-form-field>

.ts

  enableInput = false;

I have multiple checkboxes display using ngFor, not sure if this affects, just need either one of the checkbox is checked to enable the matInput. My current method will checked all the checkbox in one click, and disabled the input after check, tried the opposite way but doesn't work as well.




Aucun commentaire:

Enregistrer un commentaire