Reputation: 2698
I am very new to angular and trying to pass the value of the Cancel button to angular. I have the following code in Cancel button
<button class="appBtn" mat-button [mat-dialog-close] ="data">
Cancel
</button>
I want to capture the button value Cancel on the angular so that can make some variables null. Is it possible to do this or is thier a different way?
Upvotes: 0
Views: 90
Reputation: 9367
Why don't you just pass it with the data?
<button class="appBtn" mat-button [mat-dialog-close]="{btn: 'cancel', data: data}">
Cancel
</button>
Supposing this is the code that fired the dialog in the first place:
showDialog() {
const dialogRef = this._matDialog.open(MyDialogComponent);
dialogRef.afterClosed().subscribe((value) => {
console.log({'pressed button': value.btn, data: value.data});
});
}
Upvotes: 1
Reputation: 6641
Add a click event handler on your button and perform operations in its handling function.
<button class="appBtn" mat-button [mat-dialog-close] ="data" (click)="onClick($event)">
Cancel
</button>
Component:
onClick(event) {
// Capture button name.
var buttonName = event.target.name;
// Make variables null.
}
Upvotes: 0