使用angular6中的预选数据选择复选框

时间:2018-12-28 07:43:38

标签: javascript angular angular6 primeng

我要在复选框中显示角色列表,如果已经选择了角色,则选中该复选框。

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>

出什么问题了?我该如何解决这个问题?

1 个答案:

答案 0 :(得分:-1)

您应将具有字符串格式的id推送到selectRoleValue

this.selectRoleValue.push(el + '');