【问题标题】:How to bind the checkbox values in angular4如何在angular4中绑定复选框值
【发布时间】:2018-03-05 12:12:07
【问题描述】:

您能否分享如何在角度中绑定复选框值的代码?一旦我绑定复选框值,它只显示真或假。如何绑定angular4中的值?

【问题讨论】:

  • 复选框只能为真(选中)或假(未选中)
  • 如何在angular中绑定多个勾选的值?
  • 如果您遵循 Angular 教程,我很确定它会告诉您如何执行数据绑定等基本任务
  • 使用 ngModel 将数据绑定到模板'
  • check this,猜猜这就是你所期待的

标签: angular angular4-forms


【解决方案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

}

【讨论】:

    猜你喜欢
    • 2015-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-11
    • 2011-11-16
    • 1970-01-01
    • 2019-09-20
    相关资源
    最近更新 更多