Varathan Swaminath Varathan Swaminath - 1 year ago 102
Node.js Question

How to clear $rootScope completely when my application gets signout

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.My Logout Code


You should delete your properties from $roorScope. It should be:

delete $rootScope.yourProperty1;
delete $rootScope.yourProperty2;

I 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];