In my angular.js application, I have implemented multiple views and I am in need of maintaining the status across view changes. To achieve this, I have created a simple factory to share data between controllers. Instead of using "$scope" in the controllers, I utilize the factory name:
app.factory('share', function() {
return {};
}
app.controller('FirstCtrl', function ($scope, share) {
share.obj1['a'] = 'ABC';
});
app.controller('SecondCtrl', function ($scope, share) {
share.obj1['b'] = 'DEF';
if (share.obj1['a'] === 'ABC') {
...
}
});
The structure of my HTML view is as follows:
...
<div ng-repeat="(key, item) in obj1">
{{item}}
</div>
...
However, it's important to note that ng-* directives within views only have access to $scope, which means that the current setup does not function as intended.
Is there a way to ensure that the data remains synchronized between the share factory and $scope?