我在角度上是新的,我真的需要帮助,在此先感谢
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),
);
}
请记住arrow function
在使用回调时用于保留上下文,因为this
(上下文)会发生变化。
this.interval = setInterval(() => this.ingameee(), 5000);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句