나는 사용자에게 추가 할 수있는 모든 회사 역할의 목록을 가지고 있으며 현재 가지고있는 역할에 대해 사용자로부터받은 목록도 가지고 있습니다. 둘 다 서비스에서 나옵니다. 이 두 목록과 존재하는 역할을 비교하여 HTML 목록에 표시 할 때 확인하고 싶습니다.체크 박스 배열의 목록 체크리스트
내 HTML :
<div class="roles-div">
<div style="text-align: center;">
<label class="label-roles">Select User Roles</label>
</div>
<form #rolesForm="ngForm" (ngSubmit)="submitRole(rolesForm)" >
<div class="flex-column-center">
<div class="flex-center width90 height300 checkbox-div">
<div>
<ul>
<li *ngFor="let role of context.roles">
<input class="roles-li" type="checkbox" [(ngModel)]="role.id" name="role">{{ role.label }}
</li>
</ul>
</div>
</div>
<div class="flex-column-center2 width35">
<button class="btn-main10" type="submit">Submit</button>
</div>
</div>
</form>
내 TS :
export class AddRolePopupComponent extends PopupAbstract<any> implements
OnInit {
userRoles = [];
constructor(private userService: UserService, private companyService: CompanyService, public dialog: DialogRef<any>) {
super(dialog, dialog.context);
}
ngOnInit() {
this.userService.getRolesForUser(this.context.id).subscribe(
response => { this.handleSucess(response); },
error => { console.error(error); },
);
}
handleSucess(response) {
this.userRoles = response;
}
submitRole(rolesForm){
console.log(rolesForm.value);
}
}
무엇을 어떻게해야이 기존 역할을 확인하려면?
당신은'context.roles'와'userRoles'를 로깅 할 수 있습니까? –
Context.roles 배열은 다음과 같습니다 역할 : 배열 (2) : {ID : "cb53681a-608f-4ea5-a9a4-3826b30684b0"이름 : "ROLE_COMPANY_ADMIN"레이블 : "회사 관리자"를 입력 : "COMPANY"} : {id : "6235e566-b668-4780-ba9a-72e7f9e5a067", 이름 : "ROLE_PROJECT_MANAGER", 레이블 : "프로젝트 관리자", 유형 : "COMPANY"} –
userRoles의 경우 handleSucess에서 .response은 ... 나에게 배열을주고있다 : ID 을 : "cb53681a-608f-4ea5을-a9a4-3826b30684b0" 라벨 을 : "회사 관리자",536,913을이름 : "ROLE_COMPANY_ADMIN" 유형 : "회사" –