如何将参数传递给重定向页面?

时间:2015-06-19 10:40:18

标签: javascript angularjs

我的脚本可以按下按钮:

 $scope.ShowDetailsAboutTicket = function (pinTicket) {
        if ($scope.showdetail == false && pinTicket != null) {
            $scope.pinTicket = pinTicket;


            $http.get(TicketUrl + 'GetTicket/' + $scope.terminalId + '/' + $scope.pinTicket)
                .success(function(data, status, headers, config) 
                {

                    $("#background").addClass("darker");
                    $scope.showdetail = true;
                    $scope.ticketNotFound = false;
                    $location.search("ticketid", pinTicket);


                })
                .error(function(data, status, headers, config) {

                    $scope.ticketNotFound = true;
                    $scope.showdetail = false;



            })
           .then(TicketDetails, ErrorResponse);

        }

    }

一切正常。我得到网址:http://localhost:60664/Home#?ticketid=8837278738但我希望当用户点击按钮将其重定向到带有这些参数的体育页面时...我该怎么做?我尝试使用window.location,但我没有得到参数

2 个答案:

答案 0 :(得分:0)

您可以将$routeParams用于此

这样的事情:

Module.controller("yourControler", ["$routeParams", function($routeParams){
  //do whatever you need with the controller

 $scope.ticketId = $routeParams.ticketId;

 $scope.dosomethingOnSubmit = function() {
   //read $routeParams.ticketId and use $location to redirect user where you need to (but that will result in GET action)

  //Or you can perform your own POST request via $http service or $resource
  //Read the docs :)
 }
}]);

然后在您的模板中引用ticketId

<a class="myButton" ng-href="some/path/?ticketId={{ticketId}}">Go to Sport page</a>

好的,如果那是提交按钮,那么你可以这样做

<form ng-submit="dosomethingOnSubmit()">
  <button type="submit">Submit</button>
</form>

ngSubmit - https://docs.angularjs.org/api/ng/directive/ngSubmit

$ http - https://docs.angularjs.org/api/ng/service/ $ http

答案 1 :(得分:0)

您应该在配置中定义路线,然后在用户点击按钮时调用该路线。

您可以使用ng-route或更多扩展版ui-router

相关问题