【发布时间】:2016-10-21 14:13:00
【问题描述】:
我正在使用 angularjs 进行身份验证,所以在连接我的用户后,我想将他重定向到主页:
$scope.submit = function(user) {
var request = {
method: 'POST',
url: 'http://localhost:9001/signIn',
headers: {
'Content-Type': 'application/json'
},
data: {
"email": user.email,
"password": user.password,
"rememberMe": true
}
};
$http(request).then(function(data) {
$location.path('/home');
}, function(error) {
console.log(error);
});
};
这是我的配置:
app.config(function($urlRouterProvider, $stateProvider, $httpProvider, $authProvider) {
$urlRouterProvider.otherwise('/home');
$stateProvider
.state('home', {
url: '/home',
templateUrl: '/home',
controller: 'HomeCtrl',
resolve: {
authenticated: function($q, $location, $auth) {
var deferred = $q.defer();
if (!$auth.isAuthenticated()) {
$location.path('/signIn');
} else {
deferred.resolve();
}
return deferred.promise;
}
}
})
.state('signIn', {
url: '/signIn',
templateUrl: '/signIn',
controller: 'SignInCtrl'
});
});
我试过了:
$http(request).then(function(data) {
$scope.$evalAsync(function() {
$location.path('/home');
});
console.log(data);
}, function(error) {
console.log(error);
});
还有:
$location.path('/home');
$location.replace();
以上工作都没有,非常感谢任何帮助。
【问题讨论】:
-
$http请求确定成功了吗?您是否将$location注入控制器?您的问题中没有体现出来。 -
是的!我认为我的权限有问题:/谢谢您的回复
-
您遇到的错误是什么?