我使用AngularJS 1.6.4
我的主页的URL是http://localhost:8080/AsumForum/
我想,如果用户已经注册成功,显示成功消息到我的网站。如果用户已注册,我会将他重定向到主页,我的网址如下所示:http://localhost:8080/AsumForum/?registered=true
。
事情是,$ location.search()永远找不到registered = true。我试图使$ locationProvider与HTML5兼容,但这也不起作用。
这是我的registration.js:
var app = angular.module('reg',[]);
app.controller('valid', ['$scope','$location','$http',
function($scope,$location,$http){
$scope.send = function(){
var date = new Date();
$scope.user.date=date.toString();
$http({
url: 'http://localhost:8080/AsumForum/webapi/users/register',
dataType: 'json',
method: 'POST',
data: $scope.user,
headers: {
"Content-Type": "application/json"
}
}).then(function success(response){
$scope.res = response.data;
$scope.satus = response.status;
console.log('RES: '+$scope.res+'\nSTATUS: '+$scope.status);
window.location="http://localhost:8080/AsumForum/?registered=true";
}, function error(response){
$scope.res = response.statusText;
console.log('Error: +'+$scope.res);
});
}
}]);
这里是我的login.js
var app = angular.module('mainPage',[]);
app.controller('regsuc',['$scope','$location',function($scope,$location){
$scope.message = '';
var show = $location.search();
for(var i in show){
console.log(i);
}
if(show==true){
$scope.message="Successfull registered! You can now log in.";
}
}]);
日志不返回任何东西。使用console.log(show)
返回[object Object]。
难道我真的必须使用路由传递参数,或者可以像我试过的那样完成吗?
注1:使用$location.url('http://localhost:8080/AsumForum/?registered=true);
重定向对我无效。
注2:使用location.search
而不是$location.search
返回?registered = true。
是控制器'参数名regsuc'越来越访问?如果你在'$ scope.message ='之前放置一个console.log,你会看到日志吗? – user2340824
它正在被访问,测试像一个千禧年时间 – Riki
'$ location.absUrl()'返回什么? – user2340824