5
我在AngularJS 2 RESTClient實現基類從API使用此方法調用數據:AngularJS 2 ZoneAwarePromise代替一個布爾值
public getInfoDataBooleanRequest(url: string): InfoDataBoolean {
return this.http.get(this.urlApiPrefix + url, this.createRequestOptions())
.toPromise()
.then(response => <InfoDataBoolean>response.json())
.catch(this.handleError);
}
其中InfoDataBoolean是具有兩個屬性的類:
export class InfoDataBoolean {
public data: boolean;
public error: string;
}
我有另一個班,我叫我的服務方法。 這個調用在我想從InfoDataBoolean中返回數據的方法中,而不是像這樣的InfoDataBoolean類。
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;
});
}
的console.log(isLogged())
輸出:
ZoneAwarePromise {__zone_symbol__state:空,__zone_symbol__value:數組[0]}
但我想從我的方法isLogged()
返回true
或false
。
我該怎麼做?