Reputation: 189
how can i change this.messages inside myfunction2??? Thanks
app.service('myservice', function() {
this.messages=[];
this.myfunction1=function(){
//Stuff
function myfunction2(){
//"How to access this.messages now?
}
}
});
Upvotes: 1
Views: 103
Reputation: 133403
You can declare a variable which will hold reference of this
which can be used latter.
app.service('myservice', function() {
//Declare a varible to hold reference
var _this = this;
this.messages = [];
this.myfunction1 = function() {
//Stuff
function myfunction2() {
//Use the reference variable
console.log(_this.messages)
}
}
});
Upvotes: 1