mercredi 28 décembre 2016

this.set is not a function error

Inside my controller I have this code to fade out a div:

popUpFadeOut: function(){
if(this.get('bid.popUpContainerOpacity') === 0){
this.set('bid.popUpContainerOpacity', 1);
this.set('bid.popUpContainerDisplay', 'block');   
setTimeout(this.fading, 1000); //popup box fades away after 1 seconds
}
},

fading: function() {
    this.set('bid.popUpContainerOpacity', 'bid.popUpContainerOpacity' - 0.1);

    if (this.get('bid.popUpContainerOpacity') <= 0)
    {
       this.set('bid.popUpContainerOpacity', 0);
       this.set('bid.popUpContainerDisplay', 'none');
    }
    else
    { 
       requestAnimationFrame(this.fading);
    }
},

Inside the fading function, I get this error:

Uncaught TypeError: this.set is not a function(…)

While I'm not an expert on the 'this' keyword, my guess is that it cannot find the function because fading gets called inside popUpFadeout, so calling this.set in fading will look for a set method inside popUpFadeOut, which does not exist.

My question is: How do I get access to the set method of my controller inside fading?




Aucun commentaire:

Enregistrer un commentaire