Search code examples
angularinputngmodel

Angular 2+ ngModel variable with special symbol


Angular can't understand property with '-' symbol in ngModel. I get error in the following input inside ngModel. How can i make this work without changing property name?

<ng-container matColumnDef="DRA0">
  <th mat-header-cell *matHeaderCellDef> DRA-0 </th>
  <td mat-cell *matCellDef="let element">
      <input autocomplete="off" [(ngModel)]='element.DRA-0' />
  </td>
</ng-container>

Solution

  • Simply wrap it with square brackets.

    <input autocomplete="off" [(ngModel)]="element['DRA-0']" />