$location.path doesn't change in a factory with AngularJS

后端 未结 4 2020
感动是毒
感动是毒 2020-12-11 06:43

My factory looks like:

\'use strict\';

angular.module(\'myApp\')
  .factory(\'httpInterceptor\',[\'$q\',\'$location\', \'$rootScope\', function($q, $locatio         


        
4条回答
  •  心在旅途
    2020-12-11 07:22

    There are certain cases where $location will not redirect if it is outside angular's apply cycle. Try wrapping the $location inside the $apply.

    $rootScope.$apply( function(){$location.path('/somelocatin'); } );
    

提交回复
热议问题