我在尝试更改模式控制器中的$rootScope时遇到了问题,根范围更改了,但在刷新页面之前不会立即反映在视图中。下面是我的代码:
.controller('LoginController',function($scope,$rootScope,$modalInstance){
$scope.close = function(){
$rootScope.authentication = true;
}
});
以及在其他控制器中打开模式的代码:
controller('myCtrl',function($scope,$modal){
$scope.openLoginModal = function(){
$scope.loginMdl= $modal.open({
templateUrl:'myview/myloginform.html',
controller:'LoginController'
});
$scope.loginMdl.result.then(
function(){},
function(){}
);
}
});
最后,用简单的HTML打开登录模式;
<div ng-controller='myCtrl'>
<button ng-click='openLoginModal()'>Login </button>
</div>
<div>
<p ng-show='authentication'> USER HAS LOGGED IN</p>
</div>
如您所见,我更改了$rootScope的“身份验证”变量,但更改不会立即反映在html视图中。可以有一些建议,请。
发布于 2015-07-23 05:38:46
试一试
$rootScope.$apply();
要应用rootscope中的更改,您必须使用上面的代码。
https://stackoverflow.com/questions/31578641
复制相似问题