Ensure that all other components executed prior to initiating the button's mousedown event

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?

Answer №1

Consider these 4 events:

  • change
  • input
  • mousedown
  • click

input happens immediately, ensuring your changes are seen right away.

mousedown occurs before change - meaning the entered value won't be captured on the first mouse down.

click occurs after change - making it a safe option to use as well.

Check out an example on stackblitz.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Angular 2 ngSubmit triggers unexpectedly on occasions when it is not supposed to

Currently, I am working on developing an Ionic 3 application with Angular 2 and TypeScript. In the app, there is a form that is responsible for sending data to our server. The issue I am facing is that whenever I click on the following button: <butto ...

This TypeScript error occurs when the props are not compatible and cannot be assigned to

Hello fellow Internet dwellers! I am a novice in the world of coding and TypeScript, seeking some assistance here. I am attempting to extract an array of objects from props, transform it into a new object with specific information, and then return it - ho ...

Modifying the property value based on the selected item from a dropdown menu in Angular 2

I am brand new to Angular 2 and I have come across the following code snippet. <select name="shape_id" (change)="changeShape()"> <option *ngFor="let shape of shapes" [ngValue]="shape.name"> {{shape.name}} </option> </s ...

I have the ability to run a MEAN application on my local machine, however, I am facing issues when

I am facing issues deploying my mean app. The API is not connecting to the frontend once deployed; however, it runs locally on port 3000. When I try to run it on port 8080 for deployment on Heroku, it doesn't work. Additionally, attempting to deploy t ...

Guide to creating the shared section of two wheels with CanvasRenderingContext2D

Is it possible to dynamically draw the shared area of two circular shapes using JavaScript and CanvasRenderingContext2D? My ultimate goal is to be able to adjust the size of the shape, ranging from a complete circle to a mere point. The desired outcome is ...

Uploading multiple strings to an Amazon S3 bucket using Node.js by piping a string

Suppose I have a simple loop similar to the one shown below: for (const i=0; i<3; i++) { to(`This incrementer is ${i}`) } At the end of the loop, I expect my file to contain: This counter is 0 This counter is 1 This counter is 2 I at ...

Tips on minimizing the vertical size of a mat field housing a mat-select dropdown

I need help reducing the height of a mat field that includes a mat-select in Angular v15. The code is directly from the material components documentation, with no alterations. It consists of a default table and default outline formfield. <mat-form-fi ...

The app.module encounters issues with selectors specified in its child module, feature.module, in Angular 5

When working with Angular, my app.component.html is kept simple: <app-child></app-child> The setup in App.module looks like this: import { ChildModule } from './child/child.module'; import { NgModule, Browser } from '@angular/ ...

Having trouble with dependencies while converting your project to a Progressive Web App using Angular?

Encountering issues with dynamically loading components using the code snippet below: this.dynamicContentPlacehold.clear(); const { AccountManagerComponent } = await import('./account-manager/account-manager.component') const factory = this.comp ...

Issues with CORS arise when using certain special characters in the URL

In my current web application, I have Angular on the client side and AWS API Gateway on the server side. I've encountered an error message: Access to XMLHttpRequest at <my destination> from origin <my origin> has been blocked by CORS pol ...

Guide to creating a type for a JSON object with nested properties in TypeScript

I have some JSON strings structured as follows: { name: 'test', url: 'http://test.org', contact: { email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0263636342766771762c616d6f" ...

Utilizing Angular with the development environment of Visual Studio 2015

Having trouble setting up my angular 2 application in visual studio 2015 (with update 1). The typescript compile is throwing an error - it says 'Cannot find module '@angular/core' at import { NgModule } from '@angular/core';. I eve ...

What could be the root of the error message "Outlet is not activated"?

As I work on developing a workflow with 4 steps in my web application, I encounter an issue when navigating from step 1 to step 4 and then back to step 1 without reloading the application. Upon repeating the path from step 1 to step 4 for the second time, ...

Angular is sending a parameter with a null value, which is not supposed to happen

My filtering system used to work well with a code that displayed items of specific status. However, I had to modify it to match a select input requirement. <ul id="dropdown-basic" *dropdownMenu class="dropdown-menu" role="menu" aria-labelledby="button- ...

How can I resolve the issue of TypeScript AngularJS component modal where the function this.$modalInstance.dismiss is not working?

After converting one of my user data entry forms into a uib-modal, I encountered an issue when trying to close the modal using the "cancel" button. The error message "this.$modalInstance.dismiss is not a function" keeps popping up. The same problem occurs ...

Tips for retrieving next-auth authOptions from an asynchronous function

I need to retrieve values from AWS Secrets Manager and integrate them into the authOptions configuration for next-auth. The code implementation I have is as follows: export const buildAuthOptions = async () => { const secrets: AuthSecrets = await getS ...

Enhance the capabilities of a basic object by incorporating a superclass through the creation of

I'm currently developing a library using Typescript 2.0 that can be utilized from both Typescript and JavaScript. Within the library, there is a class called Component and a function named registerComponent, both written in Typescript. My goal is to ...

Struggling to obtain the Variable

Trying to send a POST request to my ESP8266 HTTP Server, I need to transmit 4 variables: onhour, offhour, onminute, offminute. These variables should be retrieved from a timepicker-component imported from "ng-bootstrap" Despite numerous attempts over the ...

Having trouble selecting all checkboxes in the tree using angular2-tree when it first initializes

My goal is to have all checkboxes auto-checked when clicking the "feed data" button, along with loading the data tree. I've attempted using the following code snippet: this.treeComp.treeModel.doForAll((node: TreeNode) => node.setIsSelected(true)); ...

How can I open the Ion-datetime view for the current year without allowing the selection of a specific day?

I am currently troubleshooting an issue with an Ionic date-time picker component. Upon opening the datepicker, it defaults to showing May 2021. As I scroll to the present date, I notice a circle highlighting today's date indicating that it selects th ...