Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular get the data of the selected row in the table

Tags:

angular

Angular4 is also given * ngFor tabloda is listed. I want to get 'ID' information from incoming data. How can I do that?

<tbody>
    <tr *ngFor="let item of empleyoo">
        <th scope="row" >{{item.Id}}</th> /*this row data get*/
        <td>{{item.name}}</td>
        <td>{{item.surname}}</td>
        <td>{{item.code}}</td>
       <button type="button" class="glyphicon glyphicon-check"></button>
    </tr>       
<tbody>

Typescript

public GetId()
{
    var id=
}
like image 620
Can Kara Avatar asked Sep 15 '17 14:09

Can Kara


1 Answers

Your question is not clear but I guess all you want is:

<tbody>
    <tr *ngFor="let item of empleyoo">
        <th scope="row" >{{item.Id}}</th> /*this row data get*/
        <td>{{item.name}}</td>
        <td>{{item.surname}}</td>
        <td>{{item.code}}</td>
       <button type="button" (click)="onSelect(item)"class="glyphicon glyphicon-check"></button>
    </tr>
<tbody>);

onSelect(selectedItem: any) {
    console.log("Selected item Id: ", selectedItem.Id); // You get the Id of the selected item here
}
like image 139
Faly Avatar answered Nov 16 '22 01:11

Faly