怎么称呼功能?

时间:2015-07-08 14:40:34

标签: javascript angularjs

我有这个功能:

$scope.PinTicketSearch = function(pinTicket) {

    if (pinTicket != null) {
        ticketService.searchTicket(pinTicket)
            .then(function(response) {
                $location.search({
                    "ticketPin": pinTicket
                });
                $scope.TicketDetail = response;
                $scope.ShowDetailsAboutTicket = true;
            });
    }
}

我有这部分代码:

 if ($location.search().ticketPin)
 {

 }

如何调用此函数$scope.PinTicketSearch并从$location.search().ticketPin传递参数。我尝试使用$scope.PinTicketSearch($location.search().ticketPin),但我收到错误

  

PinTicketSearch不是一个功能

1 个答案:

答案 0 :(得分:0)

您应该使用回调,而不是if:

$scope.PinTicketSearch = function(pinTicket, success) {
    if(pinTicket != null) {
        ticketService.searchTicket(pinTicket)
            .then(function(response) {
                $location.search({
                    "ticketPin": pinTicket
                });
                $scope.TicketDetail = response;
                $scope.ShowDetailsAboutTicket = true;
                success();
            });
    }
}

和你的“如果”将是:

$scope.PinTicketSearch(pinTicket, function() {
    // your original "if" body
});