Ok, so I have an Api Service which gets a list of Offices…
export class ApiService {
public getOffices()
{
let url = ``;
let payload = {
headers: null,
params: {
"action": "getOffices"
}
};
let headers = new Headers({ "Content-Type": "application/json" });
let requestOptions = new RequestOptions({ headers: headers });
return this.http.post(url, JSON.stringify(payload.params), requestOptions)
.map(res => res.json());
}
}
and this goes to my UserController and saves as an office array,
@Injectable()
export class UserController {
offices: any[];
updateOffices() {
this.apiService.getOffices().subscribe(
data => {
// Success
this.offices = data.offices;
},
err => {
console.log("Error" + err);
}
);
}
}
now I’m trying to refresh a list of offices, but I can’t figure out how to get the list to dynamically update once the API call is complete. I need some sort of completion handler, which I think is what Observables are but I’m lost.
export class OfficesPage {
offices: any[];
doRefresh(refresher) {
this.userController.updateOffices();
this.offices = this.userController.offices;
this.officeCount = this.offices.length;
this.updateDescription();
refresher.complete();
setTimeout(() => {
refresher.complete();
}, 2000);
}
any help would be much appreciated.
Thanks