TypeError: Cannot set properties of undefined (setting 'channels')

36 views Asked by At

I am calling api to return certain json response and I can see successfull response.

 MockDataService.getChannelData(function(response){
            if(response){
                this.channels =response;
            }
        });

As soon as code hits this.channels = reponse, I get TypeError: Cannot set properties of undefined (setting 'channels')

I can't seem to figure out how to ensure scope is correct here. I can't use arrow funtions here due to platform support

1

There are 1 answers

2
Ubaid Ashraf On

Just affixing scope with bind worked

MockDataService.getChannelData(function(response) {
    if (response) {
        this.channels = response;
    }
}.bind(this));