【问题标题】:read parameter from current url in angular js and jsp从角度js和jsp中的当前url读取参数
【发布时间】:2016-08-01 17:43:21
【问题描述】:

嗨朋友们,我想从页面的当前 URL 中读取参数 angularJS。我的页面网址是 'http://localhost:9999/ADMIN_APP_0.1/Security_Question.jsp?user_id=1'.I 想在 Security_Question.jsp 中读取这个 user_id 我用谷歌搜索,我得到了一些有角度的路线,但我的代码风格和它的风格完全不同。而且我不知道路线。 忘记密码是调用安全问题页面的jsp页面

 Forgot_Password.jsp

var app = angular.module('formSubmit', []);
app.controller('forgotController',[ '$scope', '$http', function($scope, $http) {

  $scope.listOfSecurityQues=[];

    $scope.getAvailableUser = function() {
    var loginId= {
                "user_login" :$scope.loginid
        };
        window.alert(" login ::::"+loginId);

            var response = $http.post('loginController/loginidAvailable', loginId);
            response.success(function(data, status, headers, config) {

            window.location="./SecurityQuestion.jsp?user_id="+data; 

            });
            response.error(function(data, status, headers, config) {
                alert( "Exception details: " +data+"  "+status);
            });

            //Empty list data after process
            $scope.list = [];

        }; // end of getAvailableUser


        Security_Question .jsp

    var app = angular.module('formSubmit', []);
   app.controller('forgotController', ['$scope','$http',function($scope,
    $http) {
            $scope.listOfUserSecurityQues = [];

            $scope.getUserQuestions = function() 
            {
               //here i want that URL user_id
               var response = $http({method : 'GET',
               url : "loginController/getUserQuestions"+user_id
                });

               response.success(function(data, status, headers, config) {
                angular.forEach(data, function(value, key) {
                        $scope.listOfUserSecurityQues.push(value);
                    })
                })
                response.error(function(data, status, headers, config) {
                })
            };//end of getQuestions()


        } ]);

【问题讨论】:

    标签: angularjs url parameters


    【解决方案1】:

    通过使用 $location 我们可以读取 url 的参数。

        app.controller('Controller', ['$scope','$http','$location',
            function($scope, $http,$location)
            {
              $scope.Id=0;
    
              $scope.getUserQuestions=function(){
    
                        var url = $location.search();
    
                            angular.forEach(url,function(value,key){
                                $scope.Id=parseInt(value);
                                window.alert($scope.Id);
                            })  }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-09
      • 2023-03-23
      • 2020-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-09
      • 2012-09-02
      相关资源
      最近更新 更多