所以我想在函数中使用$ location.path更改AngularJS中的路由位置,但它不起作用。
app.controller('globalCtrl', function($scope, $route, $location){
$scope.changePath = function(newPath){
$location.path(newPath);
};
$scope.changePath("/login");
}
我该如何调用该函数或我应该怎么做?
答案 0 :(得分:0)
app.controller('globalCtrl', ['$scope','location', function($scope, $location){
$scope.changePath = function(newPath){
$location.path(newPath);
};
$scope.changePath("/login");
}]);
答案 1 :(得分:0)
我认为我找到了答案,所以在AngularJS 1中你不能改变函数中的$ location,所以唯一的方法是,我想,在更改$ location之后使用$ interval:
$interval(function(). {$location.hash($location.hash())},200);
所以这个功能每2ms就会对位置进行一次反应。