Within my formly setup, there is a button with a mousedown event triggering a method named "analyzeClick()"
<button *ngIf="show" (mousedown)="analyzeClick()" id={{htmlID}}>
{{label}}
</button>
Additionally, we have input fields that have a (change) event linked to a method called "saveData()"
<input id={{htmlID}} type="text" [formControl]="frmControl" (change)="saveData()" />
An issue arose where clicking on the button immediately after typing in an input field resulted in the (mousedown) event executing before the (change) event, causing problems for the analyzeClick method that requires data from saveData.
I attempted to address this by implementing a timeout as outlined in this guide
public analyzeClick(): void {
let i = 0;
(() => {
if (++i > 1) {
return;
}
setTimeout(function(){
console.log('Iteration: ' + i);
}, 15000);
this.runTheCode();
})();
}
However, the button's (mousedown) event still fires before the input's (change) event. How can I ensure the input's (change) event runs before the button's (mousedown) event in this situation?