在角JS注销清除$范围 [英] Clear $scope on logout in Angular js
问题描述
在我的控制器,我存储数据 $ $范围= parent.dossierSummaries数据;
但日志出来后,登录该应用程序 $范围。$ parent.dossierSummaries
保留相同的旧数据。
我的日志了这样
.success(功能(响应状态){
如果(response.status大于0){
变种U = $ rootScope.user.username;
$ cookieStore.remove('的myapp');
$ rootScope.user = {用户名:'',作用:0};
成功的(U);
}
其他{
错误(response.messages);
}
})
.error(功能(响应状态){
错误(['有一个错误记录你出去。']);
});
我不认为这是实现任何有效的方法。任何对象(控制器,指令,过滤器或作为事实上的JS对象)可以持有引用到另一个对象(在你的情况的用户),和一个不能确定谁轻易所有持有引用。
如果你做参考只会得到释放任何明示或当对象持有人引用被破坏。
什么你可以尝试为
$ rootScope.user.username ='';
$ rootScope.role = 0;
假设某个对象的跟踪数据将被清除,现在这个特定的对象。
In my controller I am storing data as $scope.$parent.dossierSummaries = data;
but after log out and login the application $scope.$parent.dossierSummaries
retains the same old data.
I am doing this on log out
.success( function( response, status ) {
if ( response.status > 0 ) {
var u = $rootScope.user.username;
$cookieStore.remove('myapp');
$rootScope.user = { username: '', role: 0 };
success(u);
}
else {
error(response.messages);
}
})
.error( function( response, status ) {
error(['There was an error logging you out.']);
});
I don't think there is any effective way to achieve it. Any object (controller, directive,filter or as a matter of fact any js object) can hold reference to another object (in your case user), and one cannot determine easily who all are holding reference.
The reference would only get release if you do it either explicitly or when the object holder the reference is destroyed.
What you can try is
$rootScope.user.username='';
$rootScope.role=0;
Assuming some object are tracking this specific object the data would be cleared now.
这篇关于在角JS注销清除$范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!