0
I am receiving an array from the back, containing the system users. I display this array on a group edit screen, where it displays all system users in a Multiple checkbox.
What I need to do and am not succeeding: when displaying the checkbox with all users of the system, I would like those who are already part of this group to appear as checked, while those who do not belong, do not.
Through a route, I have access to all group information, including which users are part of it.
How can I compare the array of users that are part of the group with the array of all system users, marking as checked when they are equal?
How I get the array of all system users:
this.groupService.getPermissions().subscribe(
(result: Permissions[]) => {
this.listaPermissions = result;
console.log(result);
},
(err) => {console.log(err); }
);
HTML
<!-- EXIBE LISTA DE USUÁRIOS -->
<mat-form-field>
<mat-select id=arrayUser placeholder="Usuários"
matNativeControl multiple>
<mat-option [value]="item.ID_PROFH" *ngFor="let item of arrayUser; let i=index"
(onSelectionChange)="changeArrayIDUser(i, item.ID_PROFH, $event)">{{item.USERNAME}}</mat-option>
</mat-select>
</mat-form-field>
Lucas, there are various algorithms for this. But in principle to follow the business logic and make the computer execute the routine you have it run, make a loop of type "for" or "foreach" in the received items array comparing what you received with what is to come and then you make the additions and "checked" manually if match in your comparison.
– Leonardo Getulio