2013-08-20 50 views
0

我想使它成爲可能,以便通過點擊以下其中一個「客戶端」<td> s我可以從'clients'數組中選擇特定對象並切換到新的視圖。我假設我想從ng-click開始,只是不知道該怎麼去做。另外我不會使用任何jQuery。在angularjs中選擇一個數組中的對象

<div ng-init="clients = [ 
    {firstname:'Buster', lastname:'Bluth', tagid:'4134'}, 
    {firstname:'John', lastname:'McClane', tagid:'9845'}, 
    {firstname:'Mister', lastname:'Spock', tagid:'0905'} 
    ]"></div> 
<div> 
    <div>Clients</div> 
     <table> 
      <thead> 
       <tr> 
        <th>First Name</th> 
        <th>Last Name</th> 
        <th>I-Number</th> 
       </tr> 
       </thead> 
       <tbody> 
        <tr ng-repeat="client in clients"> 
         <td>{{client.firstname}}</td> 
         <td>{{client.lastname}}</td> 
         <td>{{client.inumber}}</td> 
        </tr> 
       </tbody> 
      </table> 
     </div> 

回答

2

ng-click是正確的方法。你可以選擇的對象這樣

<tr ng-repeat="client in clients" ng-click="redirect(client)"> 

創建方法的控制器:

function ctrl($scope, $location){ 
    $scope.redirect = function(client){ 
     console.log(client); 
     $location.url('/someurl'); //this is the routing defined in the $routingProvider, you need to implement it. 
    } 
} 

請務必參閱類包含選擇這樣

<div ng-controller='ctrl'> 
外層的div
相關問題