2017-08-15 58 views
0

我使用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。

+0

是控制器'參數名regsuc'越來越訪問?如果你在'$ scope.message ='之前放置一個console.log,你會看到日誌嗎? – user2340824

+0

它正在被訪問,測試像一個千禧年時間 – Riki

+0

'$ location.absUrl()'返回什麼? – user2340824

回答

3

剛剛嘗試以下

你已經錯過了在$ location.search()

$location.search().registered 
+0

這個返回undefined – Riki

+0

你能否把你的網址粘貼在這裏.. –