错误TypeError:无法读取属性' get'未定义的

时间:2017-07-12 05:59:46

标签: angular typescript

enter image description here 错误类型错误:无法读取属性'获取'未定义的

我是新角色我真的需要帮助,并提前感谢



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 个答案:

答案 0 :(得分:2)

请注意,在使用回调时使用arrow function来保持上下文,因为this(上下文)会发生变化。

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