Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 347
Liem Avatar asked Sep 26 '19 08:09

Liem


1 Answers

not use "banana syntax"

<input type="checkbox" 
  [ngModel]="rowData.active=='true'?true:false"
  (ngModelChange)="rowData.active=$event?'true':'false'"
>
like image 137
Eliseo Avatar answered Nov 01 '22 07:11

Eliseo