0

I have an $scope.$on callback function on my mainController. wherever I call it from each controller it works perfectly. but when I call it from a modalController after opening modal , it's not working:

define(['app', 'jquery'], function (app, $) {
    app.controller('MainViewControllerUser',
        function ($scope, $location, $rootScope, $interval, MainViewFactoryUser){
        $scope.$on('loadingPage', function (event, value) {
            $scope.chartLoading = value;
        });
}
});

//----------------------- end of main Controller

 define(['app', 'underscore'], function (app, _) {
        app.controller('advertisementController',
            ['$scope', '$location', '$rootScope', '$interval', 'toaster', 'advertisementFactory', '$modal',
                function ($scope, $location, $rootScope, $interval, toaster, advertisementFactory, $modal) {
                $scope.$emit('loadingPage', true);

    }
    ]);



  app.controller('addClientCrtl',
            ['$scope', '$modalInstance', 'toaster', 'advertisementFactory',
                function ($scope, $modalInstance, toaster, advertisementFactory)
    {
                    $scope.$emit('loadingPage', true);

    }
    ]);



   });

that $scope.$emit('loadingPage', true); in the advertisementController is working nice but in addClientCrtl not working. I have to quote that modal controller is defining in adviertisementController and calling inside it

1 Answers1

2

Instead of $scope can you try $rootScope:

$rootScope.$on('loadingPage', function ({
});

$rootScope.$emit('loadingPage', true);
Arun Ghosh
  • 7,634
  • 1
  • 26
  • 38
  • 1
    or simple `$rootScope.$emit('loadingPage', true);` since it $rootscope will automatically resolve to $scope of parent if, parent calls child controller in same scope – Ekansh Rastogi Jul 21 '16 at 09:42