Can Kara
Can Kara

Reputation: 93

Angular get the data of the selected row in the table

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

Upvotes: 8

Views: 39202

Answers (1)

Faly
Faly

Reputation: 13356

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
}

Upvotes: 12

Related Questions