Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to make it possible so that by clicking on a 'client' in one of the following <td>s I can select that specific object from the 'clients' array and switch to a new view. I assume I would want to start with an ng-click, just not sure how to go about it. Also I will not be using any jquery.

<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>
share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

ng-click is the correct approach. You can get the selected object like this

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

Create a controller with the method:

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.
    }
}

Make sure you refer to the class in the outer div containing the select like this

<div ng-controller='ctrl'>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.