1

why is it that I am not redirected to other URL when I use angular.js $location.path ?

.controller('CheckCtrl', function($scope, $localStorage, $location) {
    $scope.check = function(){

        if($localStorage.hasOwnProperty("accessToken") === true) {
            alert("CheckCtrl logged in" + $localStorage.accessToken);
            $location.path("/post-report");
        }else{
            alert("CheckCtrl not logged in" + $localStorage.accessToken);
            $location.path("home.login");
        }
    };

})

Even though $localStorage.hasOwnProperty is true already since it contains token from Facebook.

I also try $location.reload() but still no luck.

user3569641
  • 892
  • 1
  • 17
  • 50
  • There are lots of the same questions here, but check [this](http://stackoverflow.com/questions/11784656/angularjs-location-not-changing-the-path) post out. – aminner Jan 23 '15 at 02:56
  • Actually, I already viewed that post and I try to add `$scope.apply` after `$location.path('home.login')` but still it doesn't work. I also `alert()` the path to check, it gives me the correct path. – user3569641 Jan 23 '15 at 02:59
  • it doesn't work for me too. – napstercake Jun 21 '15 at 23:02
  • Try the solution from @PauloOliveira in this post, http://stackoverflow.com/questions/11784656/angularjs-location-not-changing-the-path i think is the last answer. – napstercake Jun 21 '15 at 23:25

1 Answers1

1

Use this :-

$location.path("/post-report").replace();
or 
$location.path("/post-report");
if(!$scope.$$phase) $scope.$apply()

It replace your current location with the new location.

squiroid
  • 13,809
  • 6
  • 47
  • 67