Search code examples
htmlangularcheckbox

How to bind checkbox to string value in Angular7?


<input pInputText type="checkbox" [(ngModel)]="rowData.active"> active is a string. It's value is 'true' or 'false'. I wanna bind this string value to a checkbox. So how can I do that?


Solution

  • not use "banana syntax"

    <input type="checkbox" 
      [ngModel]="rowData.active=='true'?true:false"
      (ngModelChange)="rowData.active=$event?'true':'false'"
    >