Angular 如何获得$('button')。单击第6页中的(函数()

Angular 如何获得$('button')。单击第6页中的(函数(),angular,Angular,我想在按钮上写一个点击事件,就像我们以前在jquery中做的那样。 e、 g.- $“按钮”。单击函数{ //做点什么 }) 很简单 <div class="col-sm-6 col-md-6" *ngFor="let item of items"> <button class="fa fa-btc" (click)="btnClick();">{{item.name}} </button> </div> 您只需将click事件添加到按钮,

我想在按钮上写一个点击事件,就像我们以前在jquery中做的那样。 e、 g.- $“按钮”。单击函数{ //做点什么 })

很简单

<div class="col-sm-6 col-md-6" *ngFor="let item of items">
 <button class="fa fa-btc" (click)="btnClick();">{{item.name}}
  </button>
</div>

您只需将click事件添加到按钮,如下所示

<button class="fa fa-btc" (click)="executeFunc()" >{{item.name}}</button>

你可以这样做

in component.html

<div class="col-sm-6 col-md-6" *ngFor="let item of items">
 <button class="fa fa-btc" (click)="myFunction()">{{item.name}}</button>

你是说Angular的基础知识吗?你知道你可以通过阅读来学习如何使用Angular吗?我不想从html调用函数,我想从TST中单击html按钮元素。你想在组件加载时调用你的函数吗?我的html页面上有100个硬编码按钮,我想从其中任何一个调用单个函数。点击,很有趣不从html调用的Action单击
<button class="fa fa-btc" (click)="executeFunc()" >{{item.name}}</button>
executeFunc(){
}
in component.html

<div class="col-sm-6 col-md-6" *ngFor="let item of items">
 <button class="fa fa-btc" (click)="myFunction()">{{item.name}}</button>
 in component.ts

  myFunction(){
       // do something
   }