Thank for the answer. I need to learn how to use the provider than, I understand the json part. The table is a ranking of football teams, does the table will automatically update with this solution ?
If you use an API to fetch the data, it should be up to date each time you fetch it. You could refresh the data in the app as often as you like, for example using a refresh button, a periodic server request (every day or week or whatever), or just pull down the latest data every time the user opens the app/view.
If you only want one element of the page, or just the data from one element on the page, you probably need to do some web scraping to grab either just that element or to grab the data from the element and convert it to json. Then in your ionic app just hit the endpoint on your server. You might be able to grab the full page via http and parse out only the data you want in Ionic but…it’ll be sketchy at best.
Also, absolutely do not ever wrap your http calls in a promise like the other use said, and don’t cache it in a local variable either.
Either just return the observable to subscribe to outside your service or call toPromise on the observable if you want a promise. The code posted is an anti-pattern nightmare.
Some good info in there. Not only does that wrapping create a bunch of extra code that you don’t need, it also swallows any errors. While your console.log would go off, any component calling this service would not be notified of the error. You can solve both of those issues by avoiding any extra wrapping and returning the promise or observable directly
Regarding caching, by caching that variable locally you’re opening yourself up to odd behavior if it changes. It’s not that you can’t cache server responses in a service, just that you should only do it if you want to access it from multiple places without hitting your server a second time, which isn’t the case here (based on the code we’ve seen).
Thanks for the info about observable and promise but i really don’t know how to use it… It’s my first little ionic project and I tried many things but still can’t get the table. I got this in my TS file
The promise thing was kind of a side point. The solution to your problem is:
Maybe you can elaborate what you mean by “table ranking” in case I’m confused. Could you post a link to this site you’re talking about? The concept of taking data from other webpages is referred to as “scraping” and takes a little extra work. Do some google maybe but it’s going to probably be more than we could handle easily over the forums.
Edit: Saw the page was actually in the code commented out, it’s a wordpress site so there’s no easy way for you to just grab that data. @ebellempire’s solution of finding an existing api is probably a good one, and is certainly simpler than trying to scrape data from that website.
getTableData() is a custom function that you’ll need to finish writing to suit your needs. You would deploy it using something like this.getTableData('https://www.raal.be/classement/').
It sounds like you might need to learn some fundamentals before going further here, as Ionic requires a strong understanding of Javascript at the very minimum.