I have a base class in AngularJS 2 for restClient to call data from an API using this method:
public getInfoDataBooleanRequest(url: string): InfoDataBoolean { return this.http.get(this.urlApiPrefix + url, this.createRequestOptions()) .toPromise() .then(response => <InfoDataBoolean>response.json()) .catch(this.handleError); }
where InfoDataBoolean is a class with two properties:
export class InfoDataBoolean { public data: boolean; public error: string; }
I have another class where I named my service method. This call is inside a method in which I want to return data from an InfoDataBoolean, rather than an InfoDataBoolean class like this.
public isLogged(): boolean { return this.getInfoDataBooleanRequest('islogged').then(x => { let result: InfoDataBoolean = x; if(result.error !== "1") { console.log('Success is failed'); return false; } return result.data; }); }
The output of console.log(isLogged()) :
ZoneAwarePromise {__zone_symbol__state: null, __zone_symbol__value: Array [0]}
But I want to return true or false from my isLogged() method.
How can i do this?
source share