Is it possible to update the scope variable pointing to a factory object after the factory object has been updated? In cases where there are 2 angular controllers sharing a factory object, a change made to the factory object by one controller does not reflect in the scope variable of the other controller.
Example: http://jsfiddle.net/zjm0mo10/ The expected result is "Factory foo.bar is 666" but it shows "Factory foo.bar is 555".var app = angular.module('myApp', []);
app.factory('testFactory', function(){
return {
foo: {bar:555},
}
});
function HelloCtrl($scope, testFactory)
{
$scope.bar = testFactory.foo.bar;
$scope.clickme = function()
{
alert("testFactory.foo.bar "+testFactory.foo.bar);
$scope.$apply();
}
}
function GoodbyeCtrl($scope, testFactory)
{
testFactory.foo.bar = 666;
}
<html>
<div ng-controller="HelloCtrl">
<p>Factory foo.bar is {{bar}}</p>
<button ng-click="clickme();">btn</button>
</div>
</html>