【问题标题】:Angular 2 - stop click event propagation [duplicate]Angular 2 - 停止点击事件传播[重复]
【发布时间】:2016-06-15 12:57:53
【问题描述】:
toggleCollapse(i) {
  this.toggles[i] = !this.toggles[i];
  return false;
}

我有一个带有单击事件的父“tr 标签”,它可以切换折叠状态。在里面我有一个 td 标签,它将包含一些内容。我想取消点击“td”标签时触发的点击事件。示例代码:

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

【问题讨论】:

    标签: javascript html typescript angular


    【解决方案1】:
    (click)="toggleCollapse(i, $event)"
    
    toggleCollapse(i, event) {
      this.toggles[i] = !this.toggles[i];
      event.stopPropagation();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-22
      • 2015-11-20
      • 1970-01-01
      • 1970-01-01
      • 2021-03-25
      • 2018-01-08
      • 1970-01-01
      相关资源
      最近更新 更多