mardi 12 janvier 2016

Notify component when service function is complete in angular

I writing a service which do a http query to the backend:

getPlacesForUser(){
 this.http.get("http://localhost:8080/processPlaces")
  .map(res => res.text())
  .subscribe(
    data => this.result = data,
    err => this.logError(err),
    () => console.log('Places Request completed')
  )
}

Now I want to update the components-side, if the request is completed:

processPlaces(){
 this._backendService.getPlacesForUser();
}

How can I communicate between the component and service?

Furthermore I searching for the best practice.

Aucun commentaire:

Enregistrer un commentaire