I am failing in retrieving data from Observable.
I can't find where the problem is. As far as I understand my code is correct.
private IsPrivateLocation(id: string):boolean
{
this.service.isLocationPrivate(id).subscribe(res => {
this.location = res;
});
return this.location.isPrivate;
}
this.location
is still UNDEFINED
after method call. This is service method:
public isLocationPrivate(id:string):Observable<Location>
{
return this.http.post(AppConfig.azurefunc.locationUri, {
id: id,
operatorId: AppConfig.user.operatorId
}).pipe(map(res =>res.json()));
}
Why does it still undefined? What am I doing wrong?
Update: I managed to find a workaround without waiting for observable. However, I tried all the things that were offered below and none of them worked. Maybe that has something to do with the fact that I'm using Angular2 beta.