【发布时间】:2017-02-14 15:45:18
【问题描述】:
当在 SelectNotificationCtlr 中调用 getNotification 时,我试图调用控制器“通知”内的函数。但是,在运行此程序时,我收到一条错误消息,指出在 console.log("log"); 下面的行中 $rootScope 未定义。我尝试在 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
【问题讨论】:
标签: javascript angularjs function web rootscope