我想设置两个角度控制器之间的通信(服务不是一个选项)。我拼命地失败了。
这里是我的一些代码... 我试图同时使用$发射和$广播
invoiceApp.controller('masterReportConrtoller', ['$scope', '$location', 'authService', 'usSpinnerService', 'dateService', 'settingsService','$rootScope',
function ($scope, $location, authService, usSpinnerService, dateService, settingsService, $rootScope)
////Is User Valid
////
//$rootScope.$on("masterReportConrtoller", function() {
// $scope.parentmethod();
// });
//$scope.parentmethod = function() {
// //
$scope.masterReportConrtoller.getUserDetails = function() {
debugger;
settingsService.getUserDetails().then(function (response) {
var loginData = {
userName: response.d.user.Email,
password: response.d.user.UserPassword
};
authService.login(loginData).then(function (response) {
debugger;
$scope.Limit = response.d.organization.Limit;
});
$scope.Limit = response.d.organization.Limit;
$scope.DocumentUsage = response.d.organization.DocumentUsage;
$scope.ExpirationDate = $scope.DateConvertfromJson(response.d.organization.ExpirationDate);
var fullDate = new Date();
if (fullDate <= $scope.ExpirationDate) {
$scope.ISvalidUser = false;
$rootScope.$broadcast('masterReportConrtoller', false);
}
else {
$rootScope.$broadcast('masterReportConrtoller', true);
}
});
}
}]);
invoiceApp.controller('InvoiceController', ['$scope', '$location', '$cookieStore', 'documentService', 'dialogs', 'usSpinnerService', 'settingsService', 'associatedEmailsService', '$rootScope',
function ($scope, $location, $cookieStore, documentService, dialogs, usSpinnerService, settingsService, associatedEmailsService, $rootScope) {
$rootScope.$on('masterReportConrtoller');}
你应该有一个回调函数来处理事件发生的时间。 '$ rootScope。$ on('masterReportConrtoller',function(event,data){//用数据做某事});'。 – eminlala
我可以使用页面加载事件吗? –
'event'在这种情况下是使用$ rootScope。$ broadcast('masterReportConrtoller',false)''触发的实际事件。 – eminlala