I want to have structure like
MyStruc {
action2Execute:any; // see #q3
constructor(coll: CollectionServices) {
// see #q1
}
}
and have a ServiceClass like
MyServiceClass {
constructor(public http: HttpClient) { }
myHTTPRequest(id:number):Observable<boolean>{
this.http.get<boolean>('call/my/webservice/'+id)
}
}
and a Controller class like
MyControllerClass {
constructor(private coll: CollectionServices) {}
...
execHTTP() {
new MyStruc(coll).action2Execute.apply(1);
}
}
Now my purpose is to bind action2Exectue
to the method myHTTPRequest
, call it and process the results. I have two problems with this
If I set
action2Execute
likethis.action2Execute=coll.myHTTPRequest
than I have the problem when I call it inMyControllerClass.#execHTTP()
I get an error which says:TypeError: Cannot read property 'get' of undefined
==>http
isundefined
My other problem is that by just using
apply
I do not get the results from the observable, i.e. from the HTTP request.- What type should have
action2Exectue
in the classMyStruc
?