I am pretty new in Angular and RxJS and in my code I have the following problem.
Into the ngOnInit() method I have this code snippet:
this.usersService.getAllUsers().toPromise().then(people => {
this.people = people;
this.peopleStr = people.map(person => person.complete_name);
this.loading = false;
});
That is calling the getAllUsers() method on the UserService class:
getAllUsers(): Observable<any[]> {
this.usersList = this.db.collection('Users').snapshotChanges();
return this.usersList;
}
As you can see this getAllUsers() method return an Observable so to use the then() function I converted the result of the call to this getAllUsers() into a Promise using the toPromise().
But it seems it is not working because, using the debugger, I see that it never execute the code inside the then() function
Why? What is wrong? What am I missing? How can I fix it?