我在AngularJS 2中有一个基类,restClient使用这个方法从API调用数据:
public getInfoDataBooleanRequest(url: string): InfoDataBoolean {
return this.http.get(this.urlApiPrefix + url, this.createRequestOptions())
.toPromise()
.then(response => <InfoDataBoolean>response.json())
.catch(this.handleError);
}
Run Code Online (Sandbox Code Playgroud)
其中InfoDataBoolean是一个具有两个属性的类:
export class InfoDataBoolean {
public data: boolean;
public error: string;
}
Run Code Online (Sandbox Code Playgroud)
我有另一个课,我打电话给我的服务方法.这个调用在一个方法里面,我想从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;
});
}
Run Code Online (Sandbox Code Playgroud)
输出console.log(isLogged()):
ZoneAwarePromise {__ zone_symbol__state:null,__ zone_symbol__value:Array [0]}
但是,我想回到true或false从我的方法isLogged().
我怎样才能做到这一点?
angular ×1