I used $rootScope and $scope inside many controllers and services.I have reffered many stack overflow answer for clearing all $scope and $rootScope values solution.But it doesnt work for me(solutions like $rootScope=undefined or $rootScope=''). Kindly help me out of it.
I used $rootScope and $scope inside many controllers and services.I have reffered many stack overflow answer for clearing all $scope and $rootScope values solution.But it doesnt work for me(solutions like $rootScope=undefined or $rootScope=''). Kindly help me out of it.
Share Improve this question asked Jun 10, 2016 at 4:53 Varathan SwaminathVarathan Swaminath 982 silver badges11 bronze badges 1- Please insert code into the question as text, not as an image. You should also include any error messages as text, as well, because "it doesn't work" is not a good description of the problem. – Michael Gaskill Commented Jun 16, 2016 at 6:49
3 Answers
Reset to default 4You should delete your properties from $roorScope
. It should be:
delete $rootScope.yourProperty1;
delete $rootScope.yourProperty2;
If have many properties, you should use:
for (var prop in $rootScope) {
// Check is not $rootScope default properties, functions
if (typeof $rootScope[prop] !== 'function' && prop.indexOf('$') == -1 && prop.indexOf('$$') == -1) {
delete $rootScope[prop];
}
}
You can do the following
$rootScope.$on("logout", function(){
$rootScope.userRole= undefined;});
If you wish to clear all the defined properties on $rootScope and want to retain the initial values that e with $rootScope, you can do this by deleting all the properties on $rootScope that do not start with $. As all the initial properties are defined with $.
$rootScope.$clearScope = function() {
for (var prop in $rootScope) {
if (prop.substring(0,1) !== '$') {
delete $rootScope[prop];
}
}
}
Also, have a look to this post.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745435408a4627584.html
评论列表(0条)