[英]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.