I am selected checkbox which is i want in Units and i post it to database by using angular 6. But at the time of get selected Unit checkbox by use [checked]="is_selected" not working means its not shows me which is i selected checkbox only all units are shown.
I already tried to getByProduct and tries also to check which is selected Unit in my product and is selected value = Unit_id in Unit class then its get true. its also changed to true in console. But i have problem its not changed in Unit class is_selected is true or false. and I cant initialise the Unit class to constructor as new Unit() to work fine
Product.component.ts
Productitems: Items[];
units: Array<Unit> = [];
Unititems : Unit[];
complexForm: FormGroup;
formData: FormData;
model : Items;
unit_id: number[] = [];
constructor()
{
this.model = new Items();
}
getProductByID(Id: string): Items {
let params: any = {};
params.product_id = Id;
this.unit_id = [];
this.Item_Service.getAllUnits().subscribe(response => {
this.units = response;
this.Item_Service.getProducts_ById(params).subscribe(
responce => {
this.model = responce;
this.units.forEach(x => {
this.model.unit_id.forEach(y => {
if (x.unit_id == y) {
x.IsSelected = true;
this.unit_id.push(x.unit_id);
}
})
})
},
err => { console.log(err); });
},
err => { console.log(err); });
return this.model;
}
export class Unit {
public IsSelected: boolean;
constructor() {
this.IsSelected = false;
}
}
<div class="col-lg-3 col-md-4 col-sm-4 col-xs-12" *ngFor="let item of Unititems">
<div class="form-group">
<div class="checkbox checkbox-primary">
<input id="checkbox"class="styled" type="checkbox"
(change)="onChangeunit_id(item.unit_id, $event.target.checked)"
[checked]="IsSelected">
<label for="checkbox">
</label>
</div>
</div>
</div>
Aucun commentaire:
Enregistrer un commentaire