I've been using services in AngularJS to share data between controllers. In one particular service, I want to also expose some functionality to edit the shared object. I created a simplified JSFiddle here:
http://jsfiddle.net/RichardBender/CQ6Z4/2/
angular.module('myApp', [])
.factory('myService', function() {
return {
mySharedObject:{
myText:'abc'
},
updateObject: function() {
console.log('function called');
console.log(this);
this.mySharedObject.myText = 'def';
}
};
})
I can see that the "this" when I call updateObject() is not the object literal that the service returns. I realize that I could simply make this service depend upon another service that just exposes the shared data object, but is there a way to do so without creating a second service?
Thanks, Richard