How can I do a selected in angle 4 and the data coming from a json.
my model is
export class PvuserTenant{
constructor(
public id: number,
public int_user_id: string,
public int_tenant_id: string,
public roles_user: Array<any>,
public user: any,
public tenant: any
){
}
}
the component that uses that view is
getUserTenant() {
this._route.params.forEach((params: Params) => {
let id = params['id'];
this.userTenantService.getUserTenant(id).subscribe(
response => {
if (response.code == 200) {
this.pvuserTenant = response.data;
console.log(this.pvuserTenant);
} else {
this._router.navigate(['/users-tenant']);
}
},
error => {
console.log(<any>error);
}
);
});
}
and the list of roles is
getRoles(){
this.roleService.getRoles().subscribe(
result => {
if(result.code != 200){
//console.log(result);
}else{
this.roleModelList = result.data;
//console.log(this.roleModelList);
}
},
error => {
console.log(<any>error);
}
);
}
the view of that is
<div class="form-group">
<div>Roles</div>
<select multiple [(ngModel)]="pvuserTenant.roles_user" class="form-control" name="roles" id="roles"
required>
<option *ngFor="let role of roleModelList" value="{{ role.id }}" >
{{ role.display_name }}
</option>
</select>
</div>
but it does not make me the selected of that. verifying by console if you bring the data.
[(ngModel)]="pvuserTenant.roles_user" is the next image where you see that if you bring it
and to fill the select is
<option *ngFor="let role of roleModelList" value="{{ role.id }}" >
bone
However, this only works in a simple select, but in the multiple select no, I've been dealing with that for several days and nothing I've been able to solve.