In a component I have the following:
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};
}
I want to return the data from the restCall inside getLocalEvent
to the this.localEventEdit
variable in ngOnInit
.
This is the 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)
);
}
Any ideas? At this point I can only return return {name: "asdasd", languageId: 1, locationId: 1};
but I want to return the data from the restcall.