mam klasy bazowej w angularjs 2 dla restClient do transmisji danych, z automatycznie z tym sposobem:angularjs 2 ZoneAwarePromise zamiast wartość logiczną
public getInfoDataBooleanRequest(url: string): InfoDataBoolean {
return this.http.get(this.urlApiPrefix + url, this.createRequestOptions())
.toPromise()
.then(response => <InfoDataBoolean>response.json())
.catch(this.handleError);
}
gdzie InfoDataBoolean jest klasa dwie właściwości:
export class InfoDataBoolean {
public data: boolean;
public error: string;
}
Mam inną klasę, w której nazwałem moją metodę obsługi. To wywołanie znajduje się wewnątrz metody, w której chcę zwrócić dane z InfoDataBoolean, a nie klasy InfoDataBoolean w ten sposób.
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;
});
}
Wyjście console.log(isLogged())
:
ZoneAwarePromise {__zone_symbol__state: null, __zone_symbol__value: Array [0]}
Ale chcę wrócić true
lub false
z mojego sposobu isLogged()
.
Jak mogę to zrobić?