has van
has van

Reputation: 317

ERROR TypeError: Cannot read property 'get' of undefined

enter image description hereERROR TypeError: Cannot read property 'get' of undefined

im new in angular i really need help and thanks in advance

constructor(private http: Http, private authService: AuthService, private router: Router) {
	this.token = localStorage.getItem('token');
	
	if(token){
		this.interval = setInterval(this.ingameee, 5000);
	}
}

ingameee() {
   this.http.get('http://url.com/api/matchmaking/keepalive?token='+ this.token)
          .subscribe(
              response => {
                  this.dataa = response;
                  this.mod = this.dataa.json().mod;
                  this.playersinqueue = this.dataa.json().playersinqueue;
                  this.region_id = this.dataa.json().region_id;
                  this.party_id = this.dataa.json().party_id;
                  },
              error => console.log(error),
          );

  }

Upvotes: 6

Views: 18061

Answers (1)

Pengyy
Pengyy

Reputation: 38161

keep in mind to use arrow function for keeping the context while using callbacks because this(the context) will change.

this.interval = setInterval(() => this.ingameee(), 5000);

Upvotes: 6

Related Questions