簡體   English   中英

使用angular6中的預選數據選擇復選框

[英]Select the checkbox using pre-selected data in angular6

我想在復選框中顯示角色列表,如果已經選擇了角色,則選中復選框。

我使用此代碼返回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>

有什么問題 ? 我怎么解決這個問題 ?

您可以將ID以字符串格式推送到selectRoleValue

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM