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),
);
}
To resolve your TypeError: Cannot read properties of undefined (reading '0') , go through these steps: Ensure you are using the correct variable. Perform a simple check on your variable before using it to make sure it is not undefined. Create a default value for the variable to use if it does happen to be undefined.
TypeError - Cannot read property 'then' of undefined is thrown when the caller is expecting a Promise to be returned and instead receives undefined . Let's consider the above examples. In Example 1, the getTaxAmount(price, taxRate) function, when called, should have returned a Promise that resolves to a value of 12 .
The "Cannot read property 'click' of null" error occurs when trying to call the click method on a null value. To solve the error, run the JS script after the DOM elements are available and make sure you only call the method on valid DOM elements.
The "Cannot set properties of undefined" error occurs when setting a property on an undefined value. To solve the error, conditionally check if the value is of the expected type (object or array) or has to be initialized before setting the property on it.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With