我要在复选框中显示角色列表,如果已经选择了角色,则选中该复选框。
i使用此代码返回roleId:
this.Adu.optionId=this.selectedEdit;
this.otionService.GetRolesfoOptionsID(this.Adu).subscribe((data)=>{
data.forEach(el=>{
this.selectRoleValue.push(el);
})
console.log(this.selectRoleValue)
})
此代码有效,并已用角色填充this.selectRoleValue
,但未选中此复选框。
和HTML:
<div *ngFor="let role of roles">
<p-checkbox id="checkbox" value="{{role.id}}" [(ngModel)]="selectRoleValue" label="{{role.description}}" ></p-checkbox>
</div>
出什么问题了?我该如何解决这个问题?
答案 0 :(得分:-1)
您应将具有字符串格式的id推送到selectRoleValue
this.selectRoleValue.push(el + '');