Transfer JSON data between controllers without utilizing Services or Factory in AngularJS during routing

On my Dashboard page, I have an Object. When a user clicks on the Details Page from the Dashboard, it should redirect to the Details page. I am looking to pass the JSON Object from the Dashboard Controller to the Details Controller. Is there a way to do this without utilizing Angular JS Service or factory?

myApp.controller('dashBoardController', ['$scope', function($scope) {

     $scope.detailsPage = function(Object){


     // I want this object to be available in the details page controller

        $location.path('/detailsPage');
};

}]);

myApp.controller('detailsPageController', ['$scope', function($scope) {
  //  require Object data here
}]);

Answer №1

To transfer data from one controller to another, there are several methods that can be used:

  1. Utilizing a service or factory (often the recommended approach)
  2. Using $rootScope to store values globally (not recommended)
  3. Implementing Emit & Broadcast

https://docs.angularjs.org/api/ng/type/$rootScope.Scope

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 best way to stop event bubbling in react-router-dom when using the <Link> component?

Hey there! I have a situation that I need help with. I tried putting the Link around the whole post so that I could prevent bubbling for individual buttons, but for some reason stopPropagation() is not working as intended. Following advice from another s ...

Encountering an error in AngularJS $http calls while trying to loop: TypeError - object is not functioning

Currently, I am in the process of automating the population of my app's database with Dummy Data to eliminate the manual task of adding users, friends, and more. To achieve this, I have implemented nested AngularJS $http requests that interact with my ...

Tips for calculating the canvas-relative mouse position on a CSS 3D transformed canvas

Recently decided to challenge myself by experimenting with drawing on 3D transformed canvases. After some trial and error, I managed to get it partially working. const m4 = twgl.m4; [...document.querySelectorAll('canvas')].forEach((canvas) =& ...

Tips for resolving the issue of the symbol ' displaying as &#39 in an Angular 2 application

I am currently working on an Angular application that makes API calls when a name displayed in a grid table is clicked. However, I have encountered an issue where names containing an apostrophe are being displayed incorrectly as &#39 instead. I managed ...

typescript mock extending interface

I'm currently working with a typescript interface called cRequest, which is being used as a type in a class method. This interface extends the express Request type. I need to figure out how to properly mock this for testing in either jest or typemoq. ...

How can I load a function from the HTML file that is being loaded using .load() in jQuery?

Within my main window main.html, there is a div button that, when clicked, loads another html file into a large div. This is achieved using the .load() function: $('#mainpanel').load("search.htm"); The "search.htm" file contains a function cal ...

Using v-model with an input file is not supported

Is there a solution for not being able to use v-model in an input tag with type="file"? Here is an example of the HTML code causing this issue: <input v-model="imageReference" type="file" name="file"/> ...

What is the best way to extract basic body content using AJAX?

How do I simply parse the string 1399508637585,2252? When I open the desired page, the response above is displayed in the browser. I also tested it with hurl.it: HEADERS Content-Length: 18 Content-Type: text/html; charset=utf-8 Date: Thu, 08 May 2014 00 ...

Exploring the search feature within Redux and React-Native

The search functionality in redux is giving me some trouble. I have written the following code for it, but strangely enough, it's not working properly. Interestingly, the same code works perfectly when used without redux. searchItems: (name ) => ...

JavaScript Enigma: Instantiate 2 Date variables with identical values, yet they ultimately display distinct dates on the calendar

I need some help understanding something in my screenshot. Although both tmpStart and itemDate have been assigned the same numeric value, they display different calendar dates. start = 1490683782833 -> tmpStart = "Sun Mar 26 2017 16:51:55 GMT+ ...

Using Python to Detect a Late-Rendered Image on a Webpage Using JSON

I'm currently in the process of reviewing a list of URLs to verify the presence of a specific image. So far, I have experimented with both selenium and beautiful soup but haven't been able to crack it. The appearance of the image is represented ...

Issue locating bug in JSON implementation in AS3

The piece of code I've written is: var el = event.location; var m = el.substr(el.indexOf('?Mess:')+6).replace(/%20/g,' ').replace(/%22/g,'"') ; trace('*** Going to parse: '+m); trace(JSON.parse( m ...

Display 'Div 1' and hide 'Div 2' when clicked, then reveal 'Div 2' and hide 'Div 1' when a different button is clicked

I need help figuring out how to make two separate buttons work. One button should display 'Div 1' and hide 'Div 2', while the other button should show 'Div 2' and hide 'Div 1' when clicked. My knowledge of jquery an ...

Tips for retrieving information from a dynamically created form using VUE?

Welcome Community I am working on a parent component that includes a child component. The child component dynamically renders a form with various controls from a JSON object retrieved via a Get request using Axios. My goal is to be able to read and loop ...

converting JSON values into an array of strings in JavaScript

Greetings to all! I am excited to be a part of this community as I embark on my programming journey. I haven't been able to find any information on this particular topic, so I've taken the initiative to start a new discussion. If anything seems o ...

Using jq filter to selectively extract key-value pairs in bash

After executing the given command aws ec2 describe-tags --filter "Name=resource-id,Values=i-8dh7435490fjksfd" I received this JSON response { "Tags": [ { "ResourceType": "instance", "ResourceId": "i-8dh7435490fjksf ...

PHP - JSON does not create any output

I have developed a code that displays all the appointments I have for the day. The calendar layout is already set up. However, when I try to run the program using Python, it doesn't function as intended. Here is my code: <?php mysql_connect(dele ...

Exploring Pandas capabilities with complex nested JSON structures

I have this specific dataset that includes the following information: {'Result': { 'j': {'confirmed': true, 'version': '1'}, 'z': {'confirmed': false, &a ...

Unraveling JSON with Swift 4

Could anyone assist me in identifying what's causing the issue with this code? My goal is to extract JSON data from the server and store the values into variables. Upon running the code, no errors are displayed. However, when I attempt to print(users) ...

Leveraging Trustpilot TrustBoxes within a Next.js environment

I'm currently implementing a Trustpilot TrustBox into a Next.js application. Inside my componentDidMount, I have the following code: var trustbox = document.getElementById('trustbox'); window.Trustpilot.loadFromElement(trustbox); In the ...