1

I am trying to call the function inside the controller 'Notification' when getNotification is called in the SelectNotificationCtlr. However when running this I get an Error stating that $rootScope is undefined on the line below console.log("log");. I have tried passing the $rootScope as a parameter in my getNotification function but still receive the same error.

Please see my code below, any advice or help would be really appreciated.

app.js

selectNotification.controller('selectNotificationCtlr', ['$scope', '$rootScope', 'notificationsService',
    function($scope, $http, notificationsService, notificationService, $rootScope) {
        $scope.getNotification = function() {
            var id = $scope.selectedNotification;
            notificationData = notificationsService.getNotifications();
            console.log(notificationData);

            console.log("log");
            $rootScope.$emit("call", {});
        }
    }
]);


selectNotification.controller('Notification', ['$scope', '$rootScope',
    function($scope, $rootScope) {
        $rootScope.$on("call", function() {
            $scope.parent(notificationService);
        });

        $scope.parent = function() {
            console.log("log");
        }
    }
]);

Kind regards

CB

1 Answer 1

3

Your controller should have dependencies in the right order,

selectNotification.controller('selectNotificationCtlr', ['$scope', '$rootScope', 'notificationsService',
    function($scope, $rootScope, notificationsService) {
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, works perfectly. Something so simple, yet easily overlooked. Again thank you, morning is 100% better now.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.