I am using a Factory in Angular JS to share data between 2 controller/sub-views using router-ui.
Factory:
app.factory('SharedData', function() {
return {data: {}};
})
JobsController:
app.controller("JobsController", function($scope, $http, $resource, $location, $stateParams, JobsService, $state, SharedData) {
SharedData.data = JobsService.query();
$scope.data = SharedData.data;
});
NavController:
app.controller("navController", function($scope, $state, SharedData) {
$scope.data = SharedData.data;
});
jobs.html
{{data.jobs.length}} // this updates fine
nav.html
{{data.jobs.length}} // this does not update
Instead I have to do this:
NavController:
app.controller("navController", function($scope, $state, SharedData) {
$scope.data = SharedData;
});
jobs.html
{{data.jobs.length}} // this works fine
nav.html
{{data.data.jobs.length}} // this now works but not sure why the extra 'data' is needed?
Obviously I'm doing something wrong here but I can't figure out what despite googling for quite a few hours... can anyone help?