Surprising results from combining ng-mousedown with ng-click

I am working with the following HTML structure:

<label ng-mousedown="mousedownHandler($event)"
       ng-click="clickHandler($event)">
    <input type="checkbox" />
</label>

Within my scope, I have the following methods defined:

$scope.mousedownHandler = function(e) {
    console.log('mousedown');
};
$scope.clickHandler = function(e) {
    console.log('click');
};

While this plunker demonstrates success: http://plnkr.co/edit/pb02Zy6MtB322dUE4iUE?p=preview, I am facing difficulties replicating it in my own code. Despite some differences, such as not having to manually handle the checkbox model value change in the click handler.

I am unsure why using e.preventDefault() in the click handler is necessary for proper functionality. Failure to do so results in the clickHandler being triggered twice.

Interestingly, altering the order of attributes affects the behavior of the widget in my scenario. Placing ng-mousedown before ng-click causes a double mousedown event and no click, while switching their positions results in a double click event and no mousedown. Could this be an AngularJS bug or am I overlooking something crucial?

Answer №1

After some troubleshooting, I figured out the solution by myself: it turns out that the issue was caused by the AngularJS Batarang extension for Chrome.

You can find the pertinent question here: ng-mousedown handler attaching to ng-mouseup's event. Disabling the extension directly from the console didn't work for me, but turning off the entire extension from the settings resolved the problem.

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

What is the proper way to set up state with localStorage in Nuxt.js when using Universal Rendering?

Unique Situation In my unique setup, I have a specific flow that involves storing a token in localStorage, even though I know it's not the recommended practice. Every time my Nuxt App is launched, I need to retrieve the token from localStorage, valid ...

Counting gettext values up to a specified number of occurrences

When clicking a button, the elements within this div receive number values. If a specific pattern is reached in the text of these elements, the test should be ended. For instance, if there are 5 elements under the "someelement" div and three of them conta ...

Disabling a button when the specified class condition is met

I am currently developing an application that allows users to add individuals from an API to a list within the app. Each time a person is added, a new Bootstrap card is generated. I am currently facing a challenge regarding how to disable the "Watch Stream ...

Create directories in a nested structure using a multi-level JSON object with async.js

DEFINITION NewMethod#generateDirectoriesFromJSON (data, cb); data: JSON object. cb: Callback function. Parameters: err (Error), directoriesCreated (Boolean, true if at least one directory has been created). Assuming that the NewMethod class includes a ...

How can I target only one mapped item when using onClick in React/NextJS?

Apologies if this question is repetitive, but I couldn't find a better way to phrase my issue. The code in question is as follows: const [isFlipped, setFlipped] = useState(false); const flip = () => { if (!isFlipped) { setFlipped(tr ...

Error: Collection2 validation did not pass: The field 'name' must be filled in, the field 'email' cannot be empty, and the field 'message' is mandatory

I need to set up a way for visitors to send messages through my website const mongoose = require("mongoose"); mongoose.connect("MongoDb-Connection-Uri") .then(() => { console.log("mongodb connected"); }) .catch(() => { console.log("fail ...

I'm sorry, the system can't locate the authentication property because it is undefined

I'm currently facing an issue while incorporating firebase-ui into a VueJS project. My API credentials are stored in a file named config.js export default { apiKey: "*****", authDomain: "*****.firebaseapp.com", databaseURL: " ...

Using JavaScript to control the state of a button: enable or

In the process of creating a basic HTML application to collect customer information and store it in a database, I have encountered a specific user interface challenge. Once the user logs into their profile, they should see three buttons. Button 1 = Print ...

(React Native) Creating a visually appealing grid layout for displaying an array of item cards

I am working with two arrays named 'word' and 'definition' export default class Dictionary extends React.Component { constructor(props) { super(props); this.state = { word: [], definition:[], index: ...

Tips for selecting the correct row in a table while making edits using Angular

I'm currently working on an editable table feature, but I'm facing an issue where all rows turn into input fields once I start editing. How can I select only the row that I want to edit by clicking on it? Below is a snippet of my table structure ...

Issue with Laravel: Using `$request->all()` results in an empty array when called using JSON XHR

Having trouble using $.ajax and only the XMLHttpRequest for sending JSON to a Laravel controller. Keep getting 500 errors when attempting to make the request. Here's the method I'm using to send the data: const sendEdit = function(){ ...

Why is the code able to execute following the setState hook without any listener declared in the useEffect hook?

Recently, I came across an expo barcode scanner example where a function is executed after a setState hook. This puzzled me as I thought that calling the setState hook would trigger a re-render of the component. Can anyone explain why the function runs aft ...

How can I pass a DOM element as a prop in Vue 3?

As someone who is brand new to Vue, I'm exploring the possibilities. Although it's not something I typically do, I believe achieving a similar outcome in React + JSX (untested) could look like this: render() { const el = <p>Blah <a hre ...

Embedding the current page URL in a hidden input field inside a form for submission

I am currently exploring ways to pass the URL of the current page through a hidden field in order to redirect back to that page after processing the form input. Initially, I attempted using javascript:location.href, but it seems to be passing it as a liter ...

Are Gatsby Server-Side Rendering APIs and Next.js SSR the equivalent in functionality?

After mastering Gatsby Js for building an ecommerce website using the SSR method, I am now contemplating between sticking with Gatsby or switching to Next for future scalability as web technology advances and user base expands. Which option would be bett ...

organizing strings in alphabetical order using TypeScript

My md-collection is set up to display a list of emails like this: <md-collection-item repeat.for="u of user" class="accent-text"> <div class="row"> <di ...

I'm looking for ways to utilize the pageLoad function across multiple user controls

I am facing an issue with 3 usercontrols on a page. Each usercontrol has a pageLoad function in JavaScript, and the page itself also has a pageLoad function. However, only the pageLoad function of the last usercontrol that I registered is being fired, whil ...

Important notice: It is not possible to assign refs to function components. Any attempt to do so will result in failure. If you intended to assign a ref, consider

My console is showing a warning when I use the nextJs Link component. Can someone assist me in resolving this issue and providing an explanation? Here is the message from the console: https://i.stack.imgur.com/jY4FA.png Below is a snippet of my code: im ...

Steps to retrieve the final page number from ngx-pagination with Angular

Is there a way to utilize Custom templates within ngx-pagination in order to ensure that the first and last buttons function properly when clicked? Currently, I have utilized pagination-template to accomplish this... How can I dynamically determine the la ...

An issue arises when attempting to fetch data using next.js: a TypeError occurs indicating that

I'm currently working on setting up a next.js website integrated with strapi, but I've encountered an issue with my fetch request. Oddly enough, when I test the request using Postman, the data is successfully returned, indicating that the endpoin ...