如何从URL获取id并将其传递给函数?

时间:2015-06-19 07:57:04

标签: angularjs

我有问题。我有文本框,我需要输入一个引脚和按钮进行提交,当用户点击按钮时,我会得到包含该引脚数据的popupt。当用户点击该按钮时,它显示如下所示的URL:

http://localhost:60664/#?ticketid=87879578 

现在我需要处理功能,当我打开另一个窗口链接,以便能够看到该弹出窗口。我怎么能这样做?

这是我的功能,可以点击:

$scope.ShowDetails = function (pin) {
    if ($scope.showdetail == false && pin != null) {
        $scope.pin = pin;


        $http.get(Url + 'Get/' + $scope.pin)
            .success(function(data, status, headers, config) 
            {
               $("#background").addClass("darker");
                $scope.showdetail = true;
                $scope.NotFound = false;
                $location.search('pinid', pinTicket);


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

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



        })
       .then(Details, ErrorResponse);

    }

}

2 个答案:

答案 0 :(得分:0)

$location.search().ticketid

应该做的伎俩

所以如果你想检查网址是否有id,如果有,请运行一个函数

if($location.search().ticketid) {
  myFunction($location.search().ticketid);
}

答案 1 :(得分:0)

//this should provide you the params
var urlParams= $location.search(); 

//in your case, urlParams would be {ticketid: '87879578'}
//access ticketid as
var ticketId = urlParams['ticketid'] // or as $location.search().ticketid.

if(ticketId){
    // do something here
}
//if u want it to set to a different value sometime later, use following,
$location.search('ticketid', '12548585');