It’s far from a stupid question, but I think in order to answer it properly it’s necessary to restructure this code rather drastically. I don’t want to completely overwhelm you with an avalanche of concerns over what we have so far, so I would highly recommend you take the time to go through the Tour of Heroes chapter 6, which covers HTTP requests, and try to emulate the idioms you see in there as faithfully as you can.
So for the sake of figuring out the proximate cause of your immediate problem, please just take the following as temporary gospel and let us know what the results of the experiment are.
I’m going to assume that the function you posted here comes from a page decorated with @Component
. If that’s not the case, please make or find such a page and that’s where its replacement is going to go. I’m also going to assume that there’s a service (we’ll call it a Provider
to conform with your property naming) that you inject into the page constructor via something like:
class Page {
constructor(private provider: Provider) {}
}
Again, if that’s not how things are working now, please make them do so at least for the time being.
We’ll leave the internals of Provider.postData
intact, but it must have a signature that looks like this:
postData(body: any, endpoint: string): Observable<any> {
// stuff in here
}
Now onto Page
. Add the following bits to it (or change the relevant existing parts to look like this):
class Page {
infos: any;
constructor(private provider: Provider) {}
ngOnInit(): void {
this.provider.postData({aksi: "getdata"}, "proses-api.php")
.subscribe(infos => this.infos = infos);
}
}
…and in its template:
<div>{{infos | json}}</div>
Copy and paste what gets displayed in that <div>
, please. If you get errors, let us know the error message (as text, not an image).