I have 2 objects of type User:
users has a complete list of users.selectedUsers has getUsersBySid that returns a list of users from db
Therefore, I just want to note that the users specified by getUsersById : selectedUsers , and I tried this, but didn't work:
<select multiple materialize="material_select" [materializeSelectOptions]="selectedUsers" [(ngModel)]="selectedUsers" name="users"> <option value="" disabled selected>Usuarios</option> <option *ngFor="let user of users" [ngValue]="users" [selected]="selectedUsers.id === user.id">{{ user.name }} ({{ user.email }}) </option> </select>
Function that extracts users from the database:
getUsersBySid(){ this.surveyService.getUsersBySid(this.selectedSurvey) .subscribe( users => { this.selectedUsers = users; console.log(this.users); console.log(this.selectedUsers); }, error => { this.alertService.error("error cargar usuarios"); } ); }
console.log ():
users (3 user objects):
(3) [Object, Object, Object] 0:Object id:"1" name:"administrador" pass:"21232f297a57a5a743894a0e4a801fc3" __proto__:Object 1:Object 2:Object length:3 __proto__:Array(0)
selectedUsers (1 user object):
(1) [Object] 0:Object id:"1" name:"administrador" pass:"21232f297a57a5a743894a0e4a801fc3" __proto__:Object length:1 __proto__:Array(0)
edit 2: If I print both objects, I see that selectedUsers is changing, but the dropdown is not marked as selectedUsers
<select multiple materialize="material_select" [materializeSelectOptions]="selectedUsers" [(ngModel)]="selectedUsers" name="selectedUsers"> <option value="" disabled selected>Usuarios</option> <option *ngFor="let user of users" [ngValue]="user">{{ user.name }} ({{ user.email }}) </option> </select> Selected: {{selectedUsers}}<br/> Users: {{users}}
Price source share