2017-02-14 1 views
1

Ich versuche, die Funktion im Controller 'Notification' aufzurufen, wenn getNotification in SelectNotificationCtlr aufgerufen wird. Wenn ich das ausführe, erhalte ich einen Fehler, der besagt, dass $ rootScope in der Zeile unter console.log ("log") nicht definiert ist. Ich habe versucht, den $ rootScope als Parameter in meiner getNotification-Funktion übergeben, aber immer noch den gleichen Fehler erhalten.

Bitte beachten Sie meinen Code unten, jeder Rat oder Hilfe würde wirklich geschätzt werden.

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

Art

CB

Antwort

3

Ihre Controller Abhängigkeiten in Bezug auf in der richtigen Reihenfolge haben sollte,

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

Vielen Dank für die schnelle Antwort. Ich denke, dass es diese frühen Morgenstunden bei der Arbeit sind, die zu mir kommen. Es ist geschätzt. – CBainbridge

+0

Hoffe, es hat geholfen, Ihr Problem zu lösen – Sajeetharan

+0

Ja, funktioniert perfekt. Etwas so einfaches, aber leicht übersehen. Nochmals vielen Dank, der Morgen ist jetzt 100% besser. – CBainbridge

Verwandte Themen