I am using the dropdown to multiple select roles. When click an edit button, I want to 2 roles
to be checked out of 3 roles
. because the user has two roles admin, dashboards
out of admin, dashboards, user
.
I will check the roles from the server and the list of roles and if the role names are the same I will make the selected = true
. So, I can only select options that selected is true
.
How do I realize that? This code is based on Angular 8
.
typescript
this.user.roles = roles;
role Model
id: number;
name: string;
selected :boolean;
html
<div class="col-lg-6 kt-margin-bottom-20-mobile">
<mat-form-field class="mat-form-field-fluid">
<mat-select placeholder="Role"
formControlName="roles"
multiple>
<mat-option *ngFor="
let role of roles$ | async " [value]="role">
{{ role.name }}
</mat-option>
</mat-select>
<mat-error *ngIf="isControlHasError('roles','required')">
<strong>{{ 'AUTH.VALIDATION.REQUIRED_FIELD' | translate }}</strong>
</mat-error>
</mat-form-field>
</div>