简体   繁体   English

如何识别点击,表示已经点击了哪个按钮

[英]How to identify the click, means which button has been clicked

am using angular 6. 我正在使用角度6。

In customer list page i have 3 buttons, "NEW", "EDIT" ,"VIEW". 在客户列表页面中,我有3个按钮,“新建”,“编辑”,“查看”。 It will render to 1 component. 它将渲染为1个组件。

So i need to identify which button has been clicked so according to that i will change my page. 因此,我需要确定已单击了哪个按钮,以便根据其更改页面。

I am passing each row as a parameter. 我将每一行作为参数传递。

component.html component.html


<button mat-icon-button 
        matTooltip="Click to View" 
        (click)="viewCustomer(row)" 
        class="iconbutton" 
        color="primary">
  <mat-icon>visibility</mat-icon>
</button>
<button mat-icon-button 
        matTooltip="Click to Edit" 
        (click)="editCustomer(row)" 
        class="iconbutton" 
        color="primary">
  <mat-icon>edit</mat-icon>
</button>

common component 共同组成


viewCustomer(customer) {
  console.log(event.target);
  this.service.populateForm(customer);
  const dialogConfig = new MatDialogConfig();
  // dialogConfig.disableClose = true;
  dialogConfig.autoFocus = true;
  dialogConfig.width = '60%';
  this.dialog.open(CustomerComponent,dialogConfig);
}

You can simply pass 2nd argument in the click event like this: 您可以像这样在click事件中简单地传递第二个参数:

(click)="viewCustomer(row,'view')"
(click)="viewCustomer(row,'edit')"

and check condition in you component ts file 并检查组件ts文件中的条件

viewCustomer(row, type){
if(type=== 'view'){
  //logic here
} else if(type === 'edit') { 
  //other logic here
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何识别在 React 中单击了哪个菜单项? - How to identify which menu item has been clicked in React? 单击按钮组时如何识别单击了哪个按钮 - On click of button group how to identify which button is clicked 确定在jQuery中单击了哪个asp.net提交按钮 - Identify which asp.net submit button has been clicked in jquery 如何知道在* ngFor循环中单击了哪个按钮? - How to know which button has been clicked in a *ngFor loop? 如何确定单击哪个按钮的div /类 - How to determine which div/class a button has been clicked in 有没有办法确定点击了哪个Google地图标记? - Is there a way to identify which Google Map Marker has been clicked? 如何识别点击了哪个按钮? 如果该按钮进入并循环(while)并且具有 id 和 name = “enviar” 。 我需要知道点击了哪一个按钮 - how identify which button was clicked? if that button in and loop(while) and has id and name = “enviar” . I need to know which one button was clicked 如何识别在反应中单击了哪个按钮? - how to identify which button clicked in react? 根据单击循环中的哪个按钮来填充字段 - Populate field depending on which button in a loop has been clicked 使用jquery动态确定特定类的哪个按钮被点击 - Dynamically determine which button of a particular class has been clicked with jquery
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM