12

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>
3
  • remove click event on tr, u cnt hv two click events when other div is inside the other Commented Jan 3, 2017 at 9:44
  • aren't there anyway to do that. i want both of the click events Commented Jan 3, 2017 at 9:45
  • I don't think there is, use another button for addData Commented Jan 3, 2017 at 9:48

1 Answer 1

20

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()
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.