【问题标题】:Checkbox checked not working based on condition in angular根据角度条件选中的复选框不起作用
【发布时间】:2022-11-27 13:18:09
【问题描述】:

user.IsActive0 时我有这个复选框仍然选中

<input type="checkbox"  [(ngModel)]="user.IsActive" (change)="user.IsActive = $event.target.checked ? 1: 0" [checked]="user.IsActive == 1 || user.IsActive=='1' ? true : false">

我用过这个条件[checked]="user.IsActive == 1 || user.IsActive=='1' ? true : false"

但它不工作。

任何解决方案谢谢

【问题讨论】:

  • 您可以尝试删除 [(ngModel)] 绑定,因为您已经通过 (change)[checked] 绑定了吗?

标签: angular typescript


【解决方案1】:

杰·斯瓦米纳拉扬 尝试这个

<input type="checkbox" (change)="user.IsActive = !user.IsActive" [checked]="user.IsActive">

【讨论】:

    猜你喜欢
    • 2019-01-17
    • 2016-12-07
    • 1970-01-01
    • 2016-02-20
    • 1970-01-01
    • 2015-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多