Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid click for table row

I have included a button into the table row. but i want to handle onClick event for them separately. But when i click the button the table row click event is also getting fired. How to only fire only the button click element when button is clicked. Here is the code i'm using currently

<table class="table" style="width:100%;">
      <div  *ngFor="let data of Data; let j = index;">
            <tr [ngClass]="{onClickMember: data .clicked}" (click)="addData(data , j)">                
              <td width="15%">{{member.name}}</td>
                 <td width="15%"><button class="role-toggle" (click)="changeData(data , j)">{{data .role}}</button></td>

              </tr>
     </div>
</table>
like image 264
kohli Avatar asked Jan 03 '17 09:01

kohli


1 Answers

You can pass special $event object in your (click) function.

<button class="role-toggle" (click)="changeData($event, data , j)>

Catch the event in code and stop propogation

changeData(event, data, j) {
   event.stopPropagation()
}
like image 113
Chandermani Avatar answered Oct 27 '22 16:10

Chandermani