当我们使用角度和离子点击按钮时如何获取id?

Siv*_*que 1 ionic-framework angular

我使用下面的代码,当我点击时我没有得到id.

<button ion-item  (click)="goToDrivePage()" *ngFor="let eventNames of eventType.events">
          {{eventNames.id}}
       </button>
Run Code Online (Sandbox Code Playgroud)

任何身体帮助我在功能中获得id?

Aru*_*esh 9

将id值传递给函数

<div *ngFor="let eventNames of eventType.events">
  <button ion-item  (click)="goToDrivePage(eventNames.id)">
      {{eventNames.id}}
  </button>
</div>
Run Code Online (Sandbox Code Playgroud)

在ts文件中获取值

goToDrivePage(id : any){
     console.log(id);
}
Run Code Online (Sandbox Code Playgroud)