0
返回的數據在一個組件,我有以下:從REST調用
ngOnInit() {
this.route.params.subscribe(params => {
this.localEventEdit = this.getLocalEvent(+params['id'])
console.log(this.localEventEdit)
});
}
getLocalEvent(localEventId: number) {
this.restCall.get("/localevents/" + localEventId, (data) => {
this.localEventEdit = data;
});
return {name: "asdasd", languageId: 1, locationId: 1};
}
我想裏面getLocalEvent
返回從restCall數據到this.localEventEdit
變量ngOnInit
。
這是restCall.get
:
//HTTP GET Request
//Default return type is JSON
public get(path: string, callback: (data) => void, returnType: number = RestCall.RETURN_TYPE_JSON) {
this.auth.retrieveToken(path).subscribe(
tokenResponse => {
this.http.get(this.location + path, this.getRequestOptions(returnType))
.map((res: Response) => {
return this.handleResponse(res, returnType);
}).subscribe(
data => callback(data),
error => this.handleError(error)
)
},
tokenError => this.handleError(tokenError)
);
}
任何想法?在這一點上,我只能返回return {name: "asdasd", languageId: 1, locationId: 1};
,但我想從restcall返回數據。