I created a provider like this:
import {Injectable, Provider, Inject} from 'angular2/core';
import {Http, Response, Headers} from 'angular2/http';
import {Platform, Storage, SqlStorage,LocalStorage} from "ionic-angular";
@Injectable()
export class MyProvider {
constructor(@Inject(Platform)platform,@Inject(Http)http) {
this.http = http;
}
GetSomeOtherStuff() {
var headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
this.http.post(
'http://localhost:3000/getotherstuff',
{headers: headers}
).map(
(res:Response)=>res.json())
.subscribe(
(response) => {
//my response now can be used
},
(err) => {
},
() => {
}
); //end of subscribe
}
GetSomeStuff() {
var headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
this.http.post(
'http://localhost:3000/getstuff',
{headers: headers}
).map(
(res:Response)=>res.json())
.subscribe(
(response) => {
//my response now can be used
},
(err) => {
},
() => {
}
); //end of subscribe
}
I then have a page. Inside of this page I would like when a user comes to it to call the provider getstuff() and getotherstuff() functions to get some data. While the data is loading a little spinner should show, but when the requests finish the page should know about this.
@Page({
templateUrl: 'build/pages/mypage/mypage.html',
providers: [MyProvider]
})
export class MyPage {
isLoadingSpinner = False;
constructor(_providerMessages: ProviderMessages) {
//when this page is come upon I would like to get the data from getstuff and getothersstuff.
// when it loads it should go into these two varaibles to be displayed on the page.
isLoadingSpinner = True; //page is laoding so show spinner
this.first_data = //getstuff from provider when loaded
this.second_data = //getotherstuff from provider when loaded
isLoadingSpinner = false; //page is done loading
}
}
}
Essentially I would like the page to display the data when it is loaded, but when we are still waiting for the response I should be able to capture that state too so I could show the spinner