简体   繁体   English

仅在ngModel的值为true时选中此复选框

[英]Only check the checkbox if the value of ngModel is true

When my checkbox is clicked the value of my ngModel produto.checked is set to true , but in a moment this value is changed to false without a click in the checkbox. 单击我的复选框后,我的ngModel produto.checked的值将设置为true ,但是produto.checked此值将更改为false,而无需在复选框中单击。 How can i make my checkbox only check/uncheck according by my ngModel ? 我怎样才能使我的复选框仅根据ngModel检查/取消选中?

I try something like: 我尝试类似的东西:

<tr *ngFor="let produto of sortedDataProduto; let i = index">
   <input [checked]="produto.checked" [(ngModel)]="produto.checked" name="checkedproduto{{i}}" type="checkbox">
</tr>

Delete from your code [checked]="produto.checked ". 从您的代码中删除[checked]="produto.checked ”。 [(ngModel)]="produto.checked" is enough to show initial value. [(ngModel)]="produto.checked"足以显示初始值。

You are binding your produto.checked twice use either [checked] or [(ngModel)] 您正在绑定您的produto.checked使用[checked][(ngModel)]两次[checked]
if you still have problem please be more specific. 如果您仍然有问题,请更具体。

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

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