I want to know how can I get the value of a variable that is inside a service, I have the following code:
myModule.service('notify', ['$window', function(win) {
var msgs = []; // I want to read this variable
this.message = function(msg) {
msgs.push(msg);
if (msgs.length == 3) {
win.alert(msgs.join("\n"));
msgs = [];
}
};
}]);
and I want to read the msgs variable from a controller.
getMessages()method thatreturn msgs;messagemethod is mutating themsgsarray is indeed undesired and should be avoided. Yet, exposingmsgsusing a method precisely answers the question.