I noticed that button gets classes cdk-focused and cdk-program-focused added after the dialog it triggered is closed. If I click anywhere effect disappears.
app.component.html [fragment]
<mat-cell *matCellDef="let element">
<span matTooltip="Delete" matTooltipPosition="right">
<button mat-icon-button color="warn" (click)="openDeleteAssociationDialog()">
<mat-icon>delete</mat-icon>
</button>
</span>
</mat-cell>
Let’s add changes in the Angular component. In Html template component- app.component.html: Added click event to a button with event binding syntax i.e bracket () symbol the event name is the name of the function placed inside the bracket. This function is called when the button is clicked.
This page will walk through Angular unit test example for button click. For click event we can use triggerEventHandler method of Angular DebugElement class. We can also call native JavaScript click method of button. On click of button, we call a component method and it is possible that our component method has other dependencies to execute.
Find the method syntax from Angular doc. The first argument is the event name to trigger and the second argument is the event object passed to handler. Find the sample code. 3. Button Click Test for Property Binding For button click test we have created a component that have three button. We are creating three test scenarios. 1.
The fakeAsync is the Angular testing API that wraps a test function in a fake asynchronous test zone. The tick () simulates the asynchronous passage of time. Find the button click test code to call a component method. Now we will test Edit button of our component. On click of Edit button, we are calling a function with arguments.
<button #changeButton mat-icon-button (click)="changeItem(element)" disableRipple>
<mat-icon>edit</mat-icon>
</button>
{ ViewChild, ElementRef } from '@angular/core';
@ViewChild('changeButton') private changeButton: ElementRef;
dialogRef.afterClosed().subscribe(result => {
this.changeButton['_elementRef'].nativeElement
.classList.remove('cdk-program-focused');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With