简体   繁体   English

复选框的选中属性未按预期工作

[英]checked property of checkbox not working as expected

  <input
   type="checkbox"
   [(ngModel)]="loc.Selected"
   [checked]="loc.Selected"
   [value]="loc.Selected"
   class="checkbox col-xs-1"
   name="Countries"
   (change)="addPrimaryLocationItems()" />{{loc.LocationName}}

In the above code snippet the checkbox was not checked inspite of that the value was true and in some cases when the value is false still the checkbox is checked. 在上面的代码片段中,尽管该值是true,但并未选中该复选框,并且在某些情况下,如果该值为false,则仍选中该复选框。

Did anyone know why i get this unstable behaviour of checked property in this. 有谁知道为什么我得到这种不稳定的检查属性的行为。

try to remove [checked]="loc.Selected" . 尝试删除[checked]="loc.Selected" use only 仅使用

<input
   type="checkbox"
   [(ngModel)]="loc.Selected"
   [value]="loc.Selected"
   class="checkbox col-xs-1"
   name="Countries"
   (change)="addPrimaryLocationItems()" />{{loc.LocationName}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM