我的脚本可以按下按钮:
$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,但我没有得到参数
答案 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)