I am storing my data inside Angular service (to share across controllers) and provide a function to update it:
.factory('DataManager', function($rootScope){
var _json = {init: 'from DataManager'};
return {
json: _json,
changeTo: function (newVal) {
_json = newVal;
console.log("Changing to ", _json);
}
};
})
Then I simply pull the data into controller:
.controller('MainCtrl', function(DataManager){
var MC = this;
MC.json = DataManager.json;
MC.changeTo = DataManager.changeTo;
})
The problem is - when MC.changeTo function is called, it does update _json variable inside the Service, but not in the controller!
Here is JSbin illustrating the problem.
Any idea what I am doing wrong here?
MC.json = object1->changeTo(object2)->_json = object2. - a better oliver