How can I clear all the AngularJS $scope and $rootScope values within a single function? -
i need clear $scope
values while performing operations.
for eg: if click "signout"
button redirect "signin"
page, $scope or $rootscope values in session should cleared.
how can achieve this?
you can following:
$rootscope = $rootscope.$new(true); $scope = $scope.$new(true);
the function $new
creating new scope inheriting variables parent. true
prevents inheritance.
but not correct approach, because if use thing above, should bootstrap controllers functions manually , recreating tree of scopes.
this might useful though, idea store initialized data stored in variables , then, when assigned copied displayed variables.
the correct solution clear manually every property in each scope on logout event this: logout event:
$rootscope.$emit("logout");
catching event:
$rootscope.$on("logout", function(){ $rootscope.mydata = undefined; });
or suggested in comments, use service , cleaned.