如何绑定angular4中的复选框值

问题描述 投票:-1回答:1

你可以分享代码如何绑定角度的复选框值吗?一旦我绑定复选框值,它只显示true或false。如何绑定angular4中的值?

angular angular4-forms
1个回答
-1
投票

试试这个代码。

在模板(.html)

<input type="checkbox" [value]="item.Id" (change)="changerRoles($event)">  
 //you can bind a value using [value]

在component.ts中

changerRoles(event) {

console.log(event.target.checked)  // from event.target.checked you can get weather checkbox is checked or not
console.log(event.target.value)  // from event.target.value you can get the binded value

}
© www.soinside.com 2019 - 2024. All rights reserved.