I'm facing an issue related to typescript, where the following code is causing trouble:
private loadTeams = function(){
let token = sessionStorage.getItem('token');
if(token !== undefined && token !== null && token !== ''){
this._userService.getUserByToken(token)
.subscribe(user => {
this._teamService.getTeamsByUser(token, user)
.subscribe(data => {
this.teamList = data.data;
}, error => {
});
}, error => {
});
} else {
sessionStorage.removeItem('token');
}
}
This code snippet throws the following error:
ERROR TypeError: "_this._teamService.getTeamsByUser is not a function"
In various discussions, I have come across suggestions to use arrow functions, but isn't it already using one?
I attempted to set let that = this; and then substitute that for this in the second function, but sadly, it didn't resolve the issue.
Another workaround mentioned by people is to utilize .bind(this), yet I am unsure about where to implement this.
Could someone provide an explanation as to why this error is occurring and offer insight on how to fix it?