If I follow this particular practice of making factories:
myApp.factory('myService', function () {
var somevalue = 2;
var myServiceApi = {
theValue: somevalue,
updatevalue: updateValue
}
return myServiceApi;
function updateValue(newValue) {
somevalue = newValue;
}
});
Each and every time the service is injected the value of somevalue
is always initialized as 2, even though I have updated it earlier with the UpdateValue method. if I however use a getter method on the value it is update in all instances of the service.
http://jsfiddle.net/IngoVals/hd1r1bmp/
What is going on in the background here?