Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 - stop click event propagation [duplicate]

toggleCollapse(i) {
  this.toggles[i] = !this.toggles[i];
  return false;
}

I have a parent 'tr tag' with a click event which toggle collapse states. Inside i have a td tag which will hold some content. I want to cancel the click event trigging when clicking on 'the td' tag. Example code:

<tr *ngFor="let record of records; let i = index" class="pointer" (click)="toggleCollapse(i)">
    <td>{{record.id}}</td>
    <td>{{record.skapad}}</td>
    <td>{{record.status}}</td>
    <td (click)="cancel here">
      <pre *ngIf="!toggles[i]" class="wrap-whitespaces pointer-text">{{getShortContent(record.content)}}</pre>
      <pre *ngIf="toggles[i]" class="wrap-whitespaces pointer-text">{{record.content}}</pre>
    </td>
  </tr>
like image 845
Emanuel Weinsjö Avatar asked Aug 25 '26 12:08

Emanuel Weinsjö


1 Answers

(click)="toggleCollapse(i, $event)"
toggleCollapse(i, event) {
  this.toggles[i] = !this.toggles[i];
  event.stopPropagation();
}
like image 175
Günter Zöchbauer Avatar answered Aug 27 '26 01:08

Günter Zöchbauer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!