简体   繁体   中英

ERROR TypeError: Cannot read property 'get' of undefined

在此输入图像描述 ERROR 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), ); } 

请记住使用arrow function在使用回调时保持上下文,因为this (上下文)将会改变。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM