How to get row data from a table using angularjs

I am new to angularjs. I ran into a problem. I have a table with one switch. When the user selects any radio button and presses the submit button, I need to show data about the selected lines.

HTML code:

<table>
    <thead>
        <tr>
            <th>Select</th> 
            <th>First Name</th> 
            <th>Last Name</th> 
            <th>Unique Reference ID</th> 
            <th>Country</th> 
            <th>Branch</th> 
            <th>Card No</th> 
       </tr>
    </thead>

    <tr ng-repeat="d in Employees">
        <td><input type="radio"></td>
        <td>{{d.fname}}</td>
        <td>{{d.lname}}</td>
        <td>{{d.uniqueid}}</td>
        <td>{{d.country.name}}</td>
        <td> {{d.branch.name}}</td>
        <td>{{d.cardno}}</td> 
    </tr>
</table>

<table>
    <tr>
        <td><input type="button" value="Edit" ng-click="Edit()"></td>
    </tr>
</table>

controller code:

$scope.Edit=function()
{
    //need id of selected row ?
};
+4
source share
2 answers

Something like that:

<input type="radio" ng-click="editData.employee = d">

And the controller:

$scope.editData = {};

$scope.Edit = function() {
  var id = $scope.editData.employee.id;
};

I just answered another question about how it affects your code, which ng-repeatcreates a new scope for each list item, so you need an object for this editData. This may help you understand why you need it: Angular replace data from ng-repeat element

+5
source
0

Source: https://habr.com/ru/post/1531712/


All Articles