2017-02-14 84 views
1

我想在SelectNotificationCtlr中調用getNotification時調用控制器'通知'內的函數。但是,當運行這個時,我得到一個錯誤,說明$ rootScope未定義在console.log(「日誌」);以下的行。我曾嘗試在我的getNotification函數中將$ rootScope作爲參數傳遞,但仍然收到相同的錯誤。

請參閱下面的代碼,任何建議或幫助將非常感激。

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"); 
     } 
    } 
]); 

親切的問候

CB

回答

3

你的控制器應具有相關的正確順序,

selectNotification.controller('selectNotificationCtlr', ['$scope', '$rootScope', 'notificationsService', 
    function($scope, $rootScope, notificationsService) { 
+0

謝謝你的快速響應。我認爲這些清晨就在我的工作中。它的讚賞。 – CBainbridge

+0

希望它有助於解決您的問題 – Sajeetharan

+0

是的,完美的作品。一些非常簡單但容易被忽視的東西。再次感謝你,早上現在已經100%好多了。 – CBainbridge