Issues with Angular $parse not returning local variables

My goal is to enable the dragging functionality of an element using jQuery and Angular directives:

function dragElement($parse) {
return {
  restrict: 'A',
  link: function($scope, ele, $attr) {
    var onDragStart = $attr.onDragStart ? $parse($attr.onDragStart) : null;
    var dragData = $scope.$eval($attr.dragData) || ele;
    ele.draggable({
      containment: 'document',
      revert: true,
      helper: "clone"
    });

    ele.on("dragstart", handleDragStart);

    function handleDragStart(e) {
      if (onDragStart) {
        $scope.$apply(function() {
          var locals = {
            $event: e,
            $dragData: dragData,
          };
          onDragStart($scope, locals); //locals are defined fine here
        });
      }
    }
  }
};

}

In my controller, I have a function that triggers when I start dragging. Although the function is called correctly, the issue arises as the argument list is empty and the local variables passed in the directive are not accessible.

Controller Function

function handleFeatureDragStart($event, data) {
  console.log(arguments); //Empty
  console.log('inside handle feature start');
  console.log($event); //undefined
  console.log(data);//undefined
}

Answer №1

I cannot locate the call to your handleFeatureDragStart function.

If 'onDragStart' is the intended function, you are passing the arguments incorrectly and using them in the wrong way.

handleFeatureDragStart(e, data);

function handleFeatureDragStart(e, data) {}

The 'arguments' array is empty because no additional parameters are being passed.

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

While trying to set up a development server in Firebase, I mistakenly deleted my build folder

I recently encountered an issue with my Firebase project. While trying to set up a development server for my existing React web app that is already in production, I ran into some unexpected problems. firebase use bizzy-book-dev firebase init firebase ...

Emphasize the currently selected element in jQuery and convert its attributes into a

In an effort to enhance accessibility debugging, I've been working on a script that can identify which element has focus and display it in the console. However, I'm only interested in seeing what is printed in the HTML, not every single detail. S ...

Execute HTML code within a text field

Is it possible to run html code with javascript inside a text box, similar to w3schools.com? I am working solely with html and javascript. Thank you. For example, I have two text areas - one for inserting html, clicking a button to run the code, and displ ...

Is it not possible to generate HTML tags using jQuery and JavaScript in JSF?

I'm currently working with jsf 2.0 and richfaces 4.0 to develop my application. Occasionally, I incorporate jQuery and JavaScript functions for displaying and hiding elements. However, I've encountered an issue when trying to generate tags within ...

What potential issues can arise when importing a default export alongside a named export and using webpack in conjunction with babel?

I have two distinct constructors in my codebase: SignUp and GoogleSignIn. They are structured as follows: import SignUp, {gapi_promise} from "./SignUp"; /** * * @param element * @extends SignUp * @constructor */ function GoogleSignIn(element){ SignUp ...

Generate a dynamic text-box and drop-down list using HTML and JavaScript

My current project involves generating dynamic text-boxes based on the selection from a drop-down list and input field. https://i.sstatic.net/CMtW9.png When a user chooses 'Option 1' from the drop-down list and enters input such as 'grass& ...

Leverage OpenID Connect in Azure Active Directory with authentication code flow

Currently, I am developing an authentication system for a NodeJS and Express web application that requires users to be directed to Microsoft SSO. To achieve this, I am utilizing passport-azure-ad and OpenID Connect. My main query is - Is it mandatory to ...

The local copy of Jquery.min.js is failing to trigger the window load function

Recently, I encountered an issue with the focus of tabs while working with jQuery. Initially, everything was fine when I included: <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script> in my JSP file. The wi ...

Dynamic SVG circles with timer and progress animation

Is there a way to modify the following: var el = document.getElementById('graph'); // get canvas var options = { percent: el.getAttribute('data-percent') || 25, size: el.getAttribute('data-size') || 220, lineW ...

Tips on organizing error messages into a list within React

After receiving the response from my Spring Boot API, I need to properly format it in my React app: Array(4) 0: {field: 'lastName', message: 'size must be between 3 and 50'} 1: {field: 'username', message: 'size must be b ...

Another option instead of using useCallback

Forgive me if this is a novice inquiry, but I am still learning JavaScript and React. I recently discovered the necessity of utilizing useCallback to wrap callback functions in order to prevent them from being recreated constantly when used within a fun ...

Chinese Input Causing Triggered Computed Problem in Vue 2

Currently working with vue2 on my development project. I have noticed that the computed property only activates when Chinese input is typed, either through keyup or keydown. (example: ㄨㄛˇ => 我 It only triggers once instead of three times when f ...

Assigning the style of the parent element based on the child element

Currently, I am attempting to develop a customized dropdown field and here is the code I have come up with: const list = document.querySelector('.list'); const listItems = list.getElementsByTagName('p'); document.querySelector('# ...

What is the method for displaying a Snackbar during a Selenium test execution?

Is there a way to show a message on the screen during a Selenium test without interrupting it or needing to close any windows? I need to display a snackbar, but since I can't modify the code of the website I'm testing, using JavaScript directly i ...

How to Ensure an Element Appears Above Another Despite Z-Index Troubles?

After conducting approximately 2 hours of research on this topic, I was unable to find clear answers or solutions. Hence, I have decided to address the issue here. The problem I'm facing is as follows: Due to the nature of HTML/CSS, it seems impossi ...

Eliminate HTML TAG entries from the input form

My issue is that when I try to type a comma, it does not allow me to do so. How can I add other characters like <, >, /, \, etc? $("#in1").keypress(function (evt) { if (String.fromCharCode(evt.which) == ",") return false; }); < ...

AngularJS module dependencies are not functioning

I am encountering an issue with this code snippet: var app = angular.module("malocFeApp",['leaflet-directive']); app.controller('MainCtrl',[ "$scope", function($scope) { }]); The template is not showing up when this code is present. ...

If the td element contains text, add a comma (,) and wrap the text in HTML tags. If there

Currently diving into some jQuery code and have come across a few uncertainties. Here is what I've managed to put together so far: var html = ''; data.entities.forEach(function (value, index, array) { html += index !== data.entities.len ...

Is it possible to create a React Component without using a Function or Class

At times, I've come across and written React code that looks like this: const text = ( <p> Some text </p> ); While this method does work, are there any potential issues with it? I understand that I can't use props in this s ...

The Johnny-Five stepper initiates movement within a for-loop

I am new to using node.js and johnny-five. I want to move a stepper motor 5 times with 1000 steps each. Here is what I have tried: do 1000 Steps in cw ; console.log('ready); do 1000 steps; console.log('ready') ... It woul ...