9v-e9a
Last Updated: February 25, 2016
·
5.832K
· abayomipopoola1

Browsers history back button problem on your SPA using AngularJS.

Have you been wearied by that history back button in your fav. browser? Don't worry there are ways to get the hang of it...

var myApp = angular.module(...

Execute this code in the run block:

myApp.run(function($rootScope, $route, $location){
//Bind the $locationChangeSuccess event on the //rootScope, so that we don't need to
//bind in induvidual controllers.

$rootScope.$on('$locationChangeSuccess', function() {
$rootScope.actualLocation = $location.path();
});

$rootScope.$watch(function () {
return $location.path()}, function (newLocation) {
if($rootScope.actualLocation === newLocation) {

// run a function or perform a reload
}
});
});