Javascript $location在角度上不起作用
我有一个restapi,其中api发送重定向指令(Javascript $location在角度上不起作用,javascript,angularjs,rest,Javascript,Angularjs,Rest,我有一个restapi,其中api发送重定向指令(301正在发送) 我的js代码如下: var request = $http.post(LOGIN_URL,{username:'tes',password:'test'}) request.success(function(html) { if(html.failure) { console.log("failure") $scope.errorMessa
301
正在发送)
我的js代码如下:
var request = $http.post(LOGIN_URL,{username:'tes',password:'test'})
request.success(function(html)
{
if(html.failure) {
console.log("failure")
$scope.errorMessage = html.failure.message
}
else {
console.log("Success here....")
$location.path("route")
}
})
我可以在浏览器日志中看到它将出现在else部分(Success here…
正在打印)。但是url没有改变<代码>$location.path不起任何作用;我还尝试了$location.url
,结果也是一样的
我还将$location
注入我的控制器
我在哪里犯错
提前谢谢。试试这样的东西
$location.path("/myroute")
页面上还必须有一个ng视图。还要确保有一个与该名称对应的视图 当您注册控制器时,在控制器声明中注入了“$location”变量,如以下示例所示:
controllers.controller('MyCtrl', ['$scope', '$route', '$location', 'MYService',
function($scope, $route, $location, MyService) {
// ... controller code
}])
此外,您可能希望调试路由更改,以查看位置更改侦听器发生的情况,如本例所示:
return app.config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/home', {
templateUrl: 'partials/home.html',
controller: 'MyCtrl'
}).
when('/login', {
templateUrl: 'partials/login.html',
controller: 'LoginCtrl'
}).
when('/error/:errorId', {
templateUrl: 'partials/error.html',
controller: 'ErrorCtrl'
}).
otherwise({
redirectTo: '/home'
});
}]).run(function($rootScope, $injector, $location) {
$rootScope.$on("$locationChangeStart", function(event, next, current) {
console.log('current=' + current.toString());
console.log('next=' + next.toString());
});
});
});
ng查看页面上的
?查看此页面