2015-11-08 51 views
0

在以下代碼中,我需要將票證ID作爲方法參數。 NG點擊= 「rejectTicket({{ticket.id}})」(ofcourse這個代碼不工作)作爲參數在角度點擊方法中的表達

我想給特定的機票的ID在生成的表列到我的背結束Java控制器並調用reject()方法。任何想法如何達到這個功能「clean」的方式?

<tr ng-repeat="ticket in tickets" ng-show="ticket.state === 'NEW' || ticket.state === 'PROCESSING'"> 
    <td>{{ticket.created}}</td> 
    <td style="text-align: center;"> 
     <a href="#" ng-click="rejectTicket({{ticket.id}})"> 
      <img class="ico" src="../lib/images/reject.png" title="Reject ticket"> &nbsp; 
     </a> 
     <a href="#" ng-hide="ticket.state === 'PROCESSING'"> 
      <img class="ico" src="../lib/images/incrase.png" title="Change to processing"> &nbsp; 
     </a> 
     <span ng-show="ticket.state === 'PROCESSING'"> 
      <img class="ico" src="../lib/images/incraseDisabled.png" title="Already processing"> &nbsp; 
     </span> 
     <a href="#"> 
      <img class="ico" src="../lib/images/approve.png" title="Satisfy ticket"> 
     </a> 
    </td> 
</tr> 

EDIT 1 控制器代碼添加波紋管。

angular.module('app').controller('TicketController', function ($scope, $http, $location) { 
    $scope.tickets = []; 

    /** 
    * Get tickets. 
    */ 
    $http.get('rest/tickets').then(function (response) { 
     $scope.tickets = response.data; 
    }); 

    /** 
    * Create a ticket. 
    */ 
    $scope.createTicket = function() { 
     console.log('submit'); 
     $http({ 
      url: 'rest/tickets', 
      method: "POST", 
      data: $scope.ticket 
     }).then(function (response) { 
      $scope.tickets.push(response.data); 
     }, function() { 
      alert('Error: New ticket was not created.'); 
     }).finally(function() { 
      $scope.ticket = { 
       state: 'NEW' 
      }; 
     }) 
    }; 

    /** 
    * Reject a ticket. 
    */ 
    $scope.rejectTicket = function (ticketId) { 
     console.log('submit'); 
     $http({ 
      url: 'rest/tickets/reject', 
      method: "PUT", 
      data: ticketId 
     }).then(function (response) { 
      $scope.tickets.push(response.data); 
     }, function() { 
      alert('Error: Can not reject this ticket.'); 
     }).finally(function() { 
      $scope.ticket = {}; 
     }) 
    }; 
}); 
+1

安置自己的控制器代碼 – Sajeetharan

回答

0

你不需要在ngClick的{{}}符號所以這行: <a href="#" ng-click="rejectTicket({{ticket.id}})"> 應改爲: <a href="#" ng-click="rejectTicket(ticket.id)">