javascript - AngularJS Timing - How to make child scope see parent's $broadcast on init? -
when app starts there main template controller , child template controller. route looks this...
#/history/?q=somequery
the main template controller on init...
$rootscope.$broadcast('searchquerychanged', $location.search().q);
the child controller this...
$scope.$on('searchquerychanged', function(e, squery){ console.log(squery); });
i can see logging child controller initializes before main template controller. in theory should respond broadcast, doesn't. ideas on might doing wrong here , how fix it?
you can use $timeout provider sure $broadcast last thing executed in angular's life cycle:
$timeout(function(){ $scope.$broadcast('searchquerychanged', $location.search().q); }, 0);
Comments
Post a Comment