使用AngularJS,我有两个控制器在我的应用程序中共享相同的服务。当我触发由portalController
函数控制的事件时(请参阅 参考资料setLang()
),我没有看到 applicationController 的模型正在更新。
这个问题似乎只出现在 Firefox 和 Chrome 上。在 IE8 中它出乎意料地工作正常。
门户控制器
(function () {
'use strict';
var controllers = angular.module('portal.controllers');
controllers.controller('portalController', function portalController($scope, UserService, NavigationService, $translate) {
$scope.User = UserService.getUserinfo();
$scope.setLang = function (langKey) {
$translate.uses(langKey);
UserService.setUserinfoLocale(langKey);
UserService.getUserApplications(Constants.key_ESS);
UserService.getUserApplications(Constants.key_MED);
UserService.getUserApplications(Constants.key_SVF);
$.removeCookie(Constants.cookie_locale);
var domain = document.domain;
if (domain.indexOf(Constants.context_acc) != -1 || domain.indexOf(Constants.context_prd) != -1 || domain.indexOf(Constants.context_tst) != -1) {
domain = "." + domain;
$.cookie(Constants.cookie_locale, langKey, {path:"/", domain:domain});
} else {
$.cookie(Constants.cookie_locale, langKey, {path:"/"});
}
};
$scope.logout = function () {
NavigationService.logout();
};
$translate.uses(UserService.getUserinfoLocale());
});
//mainController.$inject = ['$scope','UserInfo'];
}());
应用控制器
(function () {
'use strict';
var controllers = angular.module('portal.controllers');
controllers.controller('applicationController', function ($scope, UserService) {
$scope.ESS = UserService.getUserApplications(Constants.key_ESS);
$scope.SVF = UserService.getUserApplications(Constants.key_SVF);
$scope.MED = UserService.getUserApplications(Constants.key_MED);
});
}());
共享的用户服务
UserService.prototype.getUserApplications = function(entity){
var locale = this.getUserinfoLocale();
return this.userApplications.query({locale: locale, entity: entity});
};