I have one controller which displays a checklist, and stores the selection in an array.
My other controller runs an $http.get
on the array from the firs
Moving some of that logic into the factory, then sending it out to all controllers with a $rootScope.$broadcast
will get your information to the correct places.
I moved the array creation into the factory, then used the $broadcast from there:
myApp.factory('FooSelection', function ($rootScope) {
var tempArr = [];
var fixArray = function(item){
if (tempArr.indexOf(item) === -1){
tempArr.push(item);
} else {
tempArr.splice(tempArr.lastIndexOf(item), 1);
}
$rootScope.$broadcast('newArray', tempArr);
}
return {fixArray: fixArray}
})
Using $scope.$on
in the controllers receives the new data when it changes:
function SimpleQueryResCtrl($scope, $http, FooSelection) {
$scope.foo_list_selection = FooSelection;
$scope.$on('newArray', function(evt, message){
console.log(message) // and you can put your $get method here
})
}
Here's the plunk