Skip to content Skip to sidebar Skip to footer

Angularjs Changing Factory Object Shared Between Controllers

Is it possible to update the scope variable that points to a factory object, after the factory object is updated? If there are 2 angular controllers which share a factory object, i

Solution 1:

Set your scope properties to testFactory.foo, eg

$scope.foo = testFactory.foo;

and

<p>Factory foo.bar is {{foo.bar}}</p>

That way, the scoped property will reference testFactory.foo which remains intact (not overwritten).

Also, you need to remove $scope.$apply() from clickme(). ng-click already triggers a digest cycle.

http://jsfiddle.net/zjm0mo10/1/

Post a Comment for "Angularjs Changing Factory Object Shared Between Controllers"