I have an add group module on which there is user list for which I am using angular2-select for multiple selections. The add group page open on click of a button. Here is the code
<ng-select [options]="users" [multiple]="true" [(ngModel)]="group.selectedUsers" placeholder="select users" name="users"></ng-select>
And I am filling with this API response data
ngOnInit() {
this.userService.getAllUsers()
.subscribe(data => {
data.forEach(element => {
this.users.push({ value: element.id, label: element.firstName});
});
})
}
Now the first time I open the add group page the user list is empty. The user list is filled after I open it the second time. Am I missing something?