ERROR TypeError: Cannot read property 'get' of undefined
我是新的角度我真的需要帮助和提前感谢
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),
);
}
1 回答
请记住在使用 callbacks 时使用
arrow function
来保持上下文,因为this
(上下文)将会改变 .