![](/img/trans.png)
[英]How do we set “True” or “False” strings to the response of a checkbox for its checked or unchecked state respectively in html?
[英]Can we use a method on [checked] property of checkbox to set it to true/false
我想在方法调用时设置复选框的 [checked] 属性,但是当我这样做时,方法被调用但它不会改变复选框的状态
HTML
<div*ngFor="let vest_style of VEST_STYLE">
<input type="checkbox" value="{{vest_style._id}}" (change)="onCheckboxChange($event,i)"
[checked]="isCheckedFromOrder(vest_style._id)"> {{vest_style.name}}
</div>
TS
isCheckedFromOrder(id) {
this.styles.value.forEach(style => {
console.log(style === id)
return style === id
})
}
我知道问题是什么。 使用以下代码代替您的代码。
let checked = false;
this.style.value.forEach(style => {
if (style == id) checked = true;
});
return checked;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.