0

I have an angular app with the name DemoProject.

I have an app.run controller and one child controller

JS

var app = angular.module("DemoProject", ['ngRoute', 'ngAnimate', 'ngMessages', 'ngMaterial']);

app.run(function ($rootScope, $route, $location, $mdDialog) {
    $rootScope.validate = true;

    $rootScope.$broadcast('eventName', { myName: 'Bala' });

});

app.controller('ChildController', function ($scope, $location, $rootScope, $document, $window) {
    $scope.myName = '';
});

I can't update the child controller scope using broadcast.

camden_kid
  • 12,591
  • 11
  • 52
  • 88
B.Balamanigandan
  • 4,713
  • 11
  • 68
  • 130

1 Answers1

3
app.controller('ChildController', function ($scope, $location, $rootScope, $document, $window) {
  $scope.myName = '';

  $rootScope.$on('eventName', function(event, args){
      console.log(args);
      $scope.myName = args.myName;
  });
});
camden_kid
  • 12,591
  • 11
  • 52
  • 88
  • In the ChildController, I received via args as per your answer. Kindly assist me, how to update the value into the property $scope.myName ? – B.Balamanigandan Feb 17 '16 at 09:57