2013-08-20 3 views
0

다음 클라이언트 중 하나에서 '클라이언트'를 클릭하여 '클라이언트'배열에서 특정 객체를 선택하고 새 객체로 전환 할 수 있도록하려고합니다. 전망. 나는 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에 클래스를 참조하십시오