我想設置兩個角度控制器之間的通信(服務不是一個選項)。我拼命地失敗了。
這裏是我的一些代碼... 我試圖同時使用$發射和$廣播
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