I just wrote one module like this:
(function(){
'use strict';
angular.module('myApp.dashboard').controller('mainControl',mainControl);
mainControl.$inject = ['whichToShow','authService'];
function mainControl(whichToShow,authService){
var self=this;
this.values=whichToShow.getVar();
this.logOut=function(){
whichToShow.setVar(false);
authService.logOutUser();
};
this.removeEvent=function(eventId){
authService.removeEvent(eventId);
}
authService.setOnAuth(authDataCallback);
// Callback to set user's events.
function authDataCallback(authData) {
if (authData) {
console.log("User is logged in with " + authData.email);
self.eventList={};
whichToShow.setVar(true);
} else {
console.log("User is logged out");
}
}
}
})();
In this module the line self.eventList={};
, at first I just use this.eventList={}
, the console tells me TypeError: Cannot set property 'eventList' of undefined
all the time.
Until I set self
as this
, and use self
in the authDataCallback function. I finally figure it out how to solve it but don't know why is this? Could you tell me?