Hello,
I’m making an Angular application and I want to load the JSON content from an external URL into my program.
from the home.components.ts file I call the service:
ngOnInit() { this.camp = this._homeService.getCamp(); console.log(this.camp); }
And the service executes the code
getCamp() { this.http.get(‘http://url.com/client/json/prov_camp.php’) .subscribe ( campERP => { this.campX = campERP; console.log(this.campX); return this.campX; } ) }
The problem is that the HTTP response can take about 30 seconds to arrive and while the whole page is loading, given that this.camp of home.components.ts is empty, but after a while it shows the result of this .campX of the service (when it has already loaded)
How can I make the program “wait” while it is loading the information from the URL?
Thank you