I am using APP_INITIALIZER like it is recommended in this answer, with my service returning a promise, but it doesn\'t always wait for it to resolve and I can see my compone
I think the problem is caused because you subscribe to the observable. This should work
@Injectable()
export class UserService {
public user: User;
constructor(private http: Http) { }
getUser(): Promise {
console.log('get user called');
return observable= this.http.get('/auth/getuser', { headers: getHeaders() })
.map(extractData)
.do(user => {
this.user = user;
console.log(this.user)
})
.toPromise();
}
}
I'm not sure if toPromise() is necessary. I'd expect it to work with Observable as well.