I want to pass a function that has an http request from a parent component to a child component, and from the child component execute the request.
My code as the following:
// myService
constructor(private http: HttpClient)
getIds(id) {
// return of(['a', 'b', 'c', id]); with this works
return this.http.get(apiUrl) // with this doesnt work
}
// parentComponent.ts
callbackFunction = this.myService.getIds;
constructor(private myService: MyService) { }
// parentComponent.html
<child-component [callbackRequest]="callbackFunction"></child-component>
// childComponent.ts
@Input() callbackRequest;
ngOnInit() {
this.callbackRequest('d');
}
What confuses me the most is that if from the service I return an observable built from of, if it works. When debugging I see that if the call to the service arrives. The error I get is the following: ERROR TypeError: Cannot read property 'get' of undefined