Exploring the $scope variable in AngularJS using JavaScript

How can I assign values to $scope.dragged and $scope.dropped in a JavaScript function?

function drag(e){
e.dataTransfer.setData("text/html", e.target.id);
console.log(e.target.id);
                $scope.dragged = e.target.className;
}
function drop(e){
e.preventDefault();
$('#relationmodal').modal('show');
e.target.className = "AAA";
var droppedon = e.target.className;
console.log(droppedon);
                $scope.dropped = e.target.className;
}

Answer №1

Coding Example

<div id="angularid" ng-app='MyModule' ng-controller="MyController">
   Hello
</div>

Programming Logic

 angular.element(document.getElementById('angularid')).scope().dragged = 'foo';

 angular.element(document.getElementById('angularid')).scope().dropped = 'bar';

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

Set the RegEx so that the entire match is non-capturing

Recently, I've been working with a regex pattern that looks like this: const newRegex = /(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/; const finalResult = "1988-02-01 12:12:12".match(newRegex); console.log(finalR ...

What is the best way to incorporate Vue Apollo into a Vue Vite project?

I'm currently working on integrating Vue Apollo into a Vite project using the composition API. Here is how my main.js file looks: import { createApp } from 'vue' import App from './App.vue' import * as apolloProvider from '../ ...

To ensure proper formatting, I must include a comma operator for numbers while typing and limit the decimal places to two

Could someone assist me in formatting a number to include commas and restrict the decimal places to two using regex? I have attempted the following, but need help making it work properly. Currently, when I enter a number it shows up as 1231244, however I ...

Is a promise already included in Angular 1.4's $http for HTTP GET requests, or do I need to create my own?

My mind is getting all tangled up the more I delve into online materials about $q and $http. If I make a $http.get call, does that automatically involve a promise? Should I also use $q in this scenario? ...

Issue with updating nested child object reference in Redux state input value

I have a function in redux that updates an object with a specified path and value. The inputs on my page are based on the values in the object stored in state. Whenever the listingObj is modified in redux, I want the DOM to automatically refresh. This i ...

Struggling to populate dropdown with values from array of objects

My issue is related to displaying mock data in a dropdown using the SUIR dropdown component. mock.onGet("/slotIds").reply(200, { data: { slotIds: [{ id: 1 }, { id: 2 }, { id: 3 }] } }); I'm fetching and updating state with the data: const ...

Trouble transferring $rootScope.currentUser between AngularJS profile and settings page

I am in the process of setting up a site using Angular, Express, Node, and Passport. Currently, I am configuring Angular to monitor the $rootScope.currentUser variable with the following code: app.run(function ($rootScope, $location, Auth) { // Watch ...

Refreshing the display in an AngularJS directive

I've developed a custom directive for handling file uploads in my AngularJS application. The directive is used in multiple places, including on the same page more than once. Each instance of the directive is supposed to display the uploaded file name ...

jQuery still not running despite using .ready

I have been attempting to run some jQuery code on my HTML page. After doing some research, I learned that using .ready may be necessary to ensure the DOM is fully loaded before executing the script. Despite this, I am still having trouble getting the scrip ...

Utilizing PHP and jQuery to dynamically populate Google Maps with multiple markers

I am currently working on integrating a Google map with a database to dynamically display multiple markers using PHP and MySQL. Below is the code I have been using: <?php //This section retrieves data from the database for later use in jQuery //CREATE ...

sending data from angular controller to a node server

Having trouble with my Angular controller that posts to the node server. The function triggering the post is giving me a 404 (Not Found) error when running it. I've tried rewriting the post multiple times but can't seem to locate the issue. If ...

Is there a way to configure MaterialUI XGrid filters to target and filter by the renderCell parameters instead of the backend data source?

While utilizing MaterialUI XGrid to showcase rows of information, I am facing an issue with filtering. Currently, filtering can only be done based on the backend row values rather than what is displayed in the cell. For instance, consider a column named U ...

Retrieving results from a Node.js application that utilizes multithreading

A new function called diversify() has been developed to execute an expensive function f() in parallel on all the cores of the machine in which it is being deployed. Additionally, a mechanism has been implemented so that when f() returns a value on one core ...

The function $scope.removeNinja cannot be found

As a beginner in Angular, I encountered an issue while working on a project that involved creating a Directory of ninjas with various functionalities implemented using Angular. Here is a snippet of my HTML file: <!DOCTYPE html> <html lang="en" n ...

Can a div be relocated within another div based on a random roll of the dice?

Hey there, I'm currently working on creating a simple Monopoly-style game. As someone who is pretty new to JavaScript, I'm looking to figure out how to move the game piece around the board based on dice rolls. Any guidance or assistance would be ...

Trouble with implementing an onclick event listener in a foreach loop

While generating and adding HTML in a for loop, I noticed that adding onclick events within the same loop is not functioning correctly: items.forEach(item => { itemHtml = `<div class="${item.id}">${item.id}</div>`; $(".it ...

Refresh the page in Angular 2

Hey there! I recently started using Angular 2 and ran into an issue with page reloads. Whenever I navigate to a different page and then press the back button, the page automatically reloads. Can someone assist me in finding a solution to prevent this fro ...

Fill the center circle with GoJs background

Is there a specific way to paint the center circle only? I have provided an example project below. ...

Resolving unexpected behavior with res.locals and pug integration

I have a function in my app.js that allows the user-id to be accessible in pug templates. app.use(function (req, res, next) { res.locals.currentUser = req.session.userId; next(); }); When logged in, I can access the id. However, when not logged in, t ...

VueJS allows for seamless image uploading using either a gallery of images or input files

Is there a way to enable image selection from "Pick from gallery" feature in addition to the file upload functionality demonstrated in the example below? I would like the same behavior for selecting an image from the gallery as when uploading a file using ...