我使用ajax调用在服务文件中执行功能,如果响应成功,我希望将页面重定向到另一个url。目前,我是通过简单的JS代码window.location = response['message'];来完成这一任务的。但我需要用AngularJS代码替换它。我看过堆叠溢出的各种解决方案,他们使用了$location。但我对AngularJS并不熟悉,在实现它方面也遇到了困难。
$http({
url: RootURL+'app-code/common.service.php',
method: "POST",
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
dataType: 'json',
data:data + '&method=signin'
}).success(function (response) {
console.log(response);
if (response['code'] == '420') {
$scope.message = response['message'];
$scope.loginPassword = '';
}
else if (response['code'] != '200'){
$scope.message = response['message'];
$scope.loginPassword = '';
}
else {
window.location = response['message'];
}
// $scope.users = data.users; // assign $scope.persons here as promise is resolved here
})发布于 2015-01-14 11:33:47
您可以使用角$window
$window.location.href = '/index.html';contoller中的示例用法:
(function () {
'use strict';
angular
.module('app')
.controller('LoginCtrl', LoginCtrl);
LoginCtrl.$inject = ['$window', 'loginSrv', 'notify'];
function LoginCtrl($window, loginSrv, notify) {
/* jshint validthis:true */
var vm = this;
vm.validateUser = function () {
loginSrv.validateLogin(vm.username, vm.password).then(function (data) {
if (data.isValidUser) {
$window.location.href = '/index.html';
}
else
alert('Login incorrect');
});
}
}
})();发布于 2015-01-14 11:37:15
发布于 2015-05-28 04:55:49
$location.path('/configuration/streaming');,这会有用的.在控制器中注入位置服务
https://stackoverflow.com/questions/27941876
复制相似问题