I have an AngularJS factory returning a simple model, which is consumed in a controller:
app.factory('myFactory1', function () {
var model = {
foo: 'original'
};
function changeModel () {
model = {
foo: 'changed'
}
// model.foo = 'changed'; would work! why?
}
// esposed API
return {
model: model,
changeModel: function () {
changeModel();
}
};
});
function FooCtrl (myFactory1) {
myFactory1.changeModel();
this.model1 = myFactory1.model // model1 not updated
}
The issue is that the view model in the controller is not updated after chnageModel() was called. Full example in this fiddle: http://jsfiddle.net/eobq064h/1/