angularjs - Reset a $rootScope property on location change in Angular.js -
in application have $rootscope property called $rootscope.currentstatus used set css class on body under circumstances.
the problem need reset value default time user leaves current page, don't know can intercept location change. use $routeprovider:
app.config(function ($routeprovider, $locationprovider, $httpprovider) { $routeprovider.when('/site/dashboard', { templateurl: '/partials/site/dashboard.html', controller: 'dashboardcntl', resolve: { loggedin: checkloggedin } }); .... });
with many entries. use resolve adding function reset variable i'd have insert in on routing entries.
do have other idea?
ok, found solution myself, can intercept location change (route change) using code:
$scope.$on('$routechangesuccess', function (next, current) { $rootscope.currentstatus = ""; });
so don't have reset variable in of routing entries, reset when route changes , set proper value inside controller.
Comments
Post a Comment