2017-02-14 26 views
1

getNotificationがSelectNotificationCtlrで呼び出されると、コントローラ '通知'内の関数を呼び出そうとしています。しかし、これを実行すると、$ rootScopeがconsole.log( "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

関連する問題