So the structure of my controller may be to blame for this. Here you can see the parent and child controllers, but the important parts are here :
Parent Controller
//Load version
$scope.person = People.people.get({ id: $routeParams.id}, function(person) {
var associations = {
events: person.events || [],
people: person.people || [],
places: person.places || []
};
$scope.$broadcast('setAssociations', associations);
});
//Event version
$scope.$on('getAssociations', function(e, args) {
var associations = {
events: $scope.person.events || [],
people: $scope.person.people || [],
places: $scope.person.places || []
};
$scope.$broadcast('setAssociations', associations);
});
Child Controller
$scope.$on('setAssociations', function(event, args) {
$scope.parentEvents = args.events;
});
$scope.$emit('getAssociations', {});
The idea is that I need to get the events
from the parent's person
object down to the child controller. The problem is, each method of raising setAssociations
from the parent only works in one context.
The load
version works if the page is navigated to from within the app (hash, navigation). However, when reloading or navigating from outside (full load), the child event is never raised, presumably because it hasn't registered its listeners yet.
The event
version works if the page is refreshed, or navigated to from outside the app (anything causing the page to fully load). When navigated to, the $scope
is empty though, and this method fails.
So the order in which the app loads the controllers is different when "deep-linking" or refreshing, and when doing internal navigation. How can I get consistent load behavior from angular controllers that have a parent child relationship?