0

In Parent controller I am getting timer value in seconds and displaying it on Index page whose controller is "ParentController".

I have added one partial view using ui-view directive. Partial view's controller is "Child controller". In our case Parent controller $broadcast request to send timer value child controller.

On first attempt it works. But When you refresh page it does not broadcast timer value to child controller.

App.controller('**parentcontroller**', function ($scope, $http, $sce, $stateParams, $state, $modal, $timeout) {
 $http.get('/home/getTimer').
    success(function (data, status, headers, config) {

 $scope.$broadcast('callTimeCountdown', {timer:data});
});
}

App.controller('**childcontroller**', function ($scope, $http, $sce, $stateParams, $state, $modal, $timeout) {


$scope.$on('callTimeCountdown', function (event, args) {

alert("In child controller");
            });
}
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
  • what do you mean it works on first attempt ? – sirrocco Sep 23 '15 at 10:12
  • when we route normally to index page (whose controller is parent controller) on first it works . But if we refresh page it doesnt call to child controller event which is second case. As we observed after refresh when $broadcast triggers by that time childcontroller was not loaded. – Vidya Patil Sep 23 '15 at 10:23
  • you should probably add some html and a plunkr would be good. How is childcontroller initiated? Are you using angular-router or ui-router ? – sirrocco Sep 23 '15 at 10:29
  • I am using ui-router – Vidya Patil Sep 23 '15 at 10:35

0 Answers0