I am calling the function below into ngoninit and binding a checkbox value with ngmodel. Here the problem is that the default checkbox is coming back as checked. I don't get where I am wrong.
Json format: [{subproducts:[{checked:true}}]]
<label for="checkbox" class="checkbox">
<input id="checkbox" type="checkbox" value="
{{newsubProduct[0].product}}" [(ngModel)]="newsubProduct[0].checked" [ngModelOptions]="
{standalone: true}" /> <i class="skin"></i><span>
{{ newsubProduct[0].product }}</span>
</label>
listproduct() {
this.Service.getData("some api").subscribe((d) => {
let mydata = d;
this.result = mydata;
this.selProducts = this.result;
for (var i = 0; i < this.selProducts.length; i++) {
let p1 = this.selProducts[i].subProducts.filter(p => p.checked);
if (!_.isEmpty(p1)) {
let p2 = p1.filter(p => {
if (p.checked) {
var checked = p.checked;
var product = p.backEndName;
this.newsubProduct.push({
checked: checked,
product: product
});
}
});
}
}
},
err => {
this.result = err;
});}
The problem is that the checkbox is checked, I expect it to be unchecked.