0

I'm getting user data from my API with Angular 2 using the following method:

getUserData()
    {
    if (this.getToken()) {
    console.log("Getting user..");
    this.http.get('thisUser?token='+this.getToken())
      .map((res:Response) => res.json())
      .subscribe(
        data => {
            this.userData = data.user;
        },
        err => { this.checkToken(err); }
      );
    }

Now, Assuming every user has points

  1. An API call has been made, my angular 2 app retrived that the user points value is 10.
  2. the user "points" (database column) value has raised from 10 points to 15.
  3. Once I got the data from my API call, the user see his number of points is 10.
  4. The app don't have a way to know if the points have changed in the database, and my angular 2 app shows that the current user has 10 points while his number of points already updated to 15, somewhere.

Any way to update this information, live?

TheUnreal
  • 23,434
  • 46
  • 157
  • 277
  • 2
    Call getUserData() every N seconds to refresh the data, using setInterval(). Or use a WebSocket to push notifications from the server to the browser (but this is harder). – JB Nizet Apr 20 '16 at 16:02
  • 1
    [See this similar question](http://stackoverflow.com/questions/35316583/angular2-http-at-an-interval?rq=1) – Ankit Singh Apr 20 '16 at 16:10

0 Answers0