I want to display a list of roles in the checkbox , If a role has already been selected, the checkbox is selected .
i using this code for return the rolesId :
this.Adu.optionId=this.selectedEdit;
this.otionService.GetRolesfoOptionsID(this.Adu).subscribe((data)=>{
data.forEach(el=>{
this.selectRoleValue.push(el);
})
console.log(this.selectRoleValue)
})
this code is work and fill the this.selectRoleValue
with role has already been selected But the checkbox is not selected.
and in HTML:
<div *ngFor="let role of roles">
<p-checkbox id="checkbox" value="{{role.id}}" [(ngModel)]="selectRoleValue" label="{{role.description}}" ></p-checkbox>
</div>
whats the problem ? how can i solve this problem ?
selectRoleValue
is true. Not ifselectedRoleValue
contains a role id. Learn how your directives work, and use a model that fits with how they work.Primeng
Componentel
? Why are you convertingselectRoleValue
to string?el
list of selected number and converttoString
just for testing[value]="role.id"
(do the same for the label while you're at it). That's the proper way to pass inputs. Note that you've posted the value of roles twice, and not the vlue of selectRoleValue.