无法调用函数,因为 $rootScope 未定义
Unable to call function as $rootScope is undefined
当在 SelectNotificationCtlr 中调用 getNotification 时,我正在尝试调用控制器内的函数 'Notification'。但是,当 运行 时,我收到一条错误消息,指出 console.log("log"); 下面的行未定义 $rootScope。我尝试将 $rootScope 作为参数传递到我的 getNotification 函数中,但仍然收到相同的错误。
请查看下面的代码,如有任何建议或帮助,我们将不胜感激。
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
您的控制器应该以正确的顺序具有依赖项,
selectNotification.controller('selectNotificationCtlr', ['$scope', '$rootScope', 'notificationsService',
function($scope, $rootScope, notificationsService) {
当在 SelectNotificationCtlr 中调用 getNotification 时,我正在尝试调用控制器内的函数 'Notification'。但是,当 运行 时,我收到一条错误消息,指出 console.log("log"); 下面的行未定义 $rootScope。我尝试将 $rootScope 作为参数传递到我的 getNotification 函数中,但仍然收到相同的错误。
请查看下面的代码,如有任何建议或帮助,我们将不胜感激。
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
您的控制器应该以正确的顺序具有依赖项,
selectNotification.controller('selectNotificationCtlr', ['$scope', '$rootScope', 'notificationsService',
function($scope, $rootScope, notificationsService) {