What is the best way to send a large amount of data to a view in Angular without the need for persistence?

One way to retrieve data in a view is by utilizing a service or making an HTTP call to a database.

Data can also be accessed through parameters in the URL or via the query string.

However, what if you need to pass a large amount of non-persistent data into a view?

For instance, suppose I have a form for creating a Thing and I want users to preview it. The show view for Thing already exists, but there's too much information to display in a modal or on the same page.

  • Using a service may seem unnecessary, and using a database definitely seems excessive.
  • Passing the data through the URL could be considered excessive as well.
  • Have you thought about using $sessionStorage?

What are your thoughts? Is there a best practice for handling this situation?

Answer №1

Utilizing a service can be a beneficial approach. The initial step involves setting the service data, while subsequent steps involve retrieving it.

If you are looking to avoid persisting the data, one option is to broadcast the data from one view (controller/directive/service) to another.

View1:

$scope.$root.$broadcast('bigdata', data);

View2:

$scope.$on('bigdata', function(e, data) {
  // Handle the data that will be automatically garbage collected after this callback ends
});

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

Upon initialization, navigate to the specified location in the route by scrolling

My page has various components stacked one after the other, such as: <about></about> <contact></contact> I am utilizing the ng2-page-scroll to smoothly scroll to a particular section when a navigation link is clicked. However, I a ...

Is it possible to modify a specific index within an array stored in Firestore?

How can I modify a specific index within an array stored in Firebase/firestore? export const editComment = (comment) => { return (dispatch, getState, { getFirebase, getFirestore }) => { const firestore = getFirestore(); firestore.collec ...

The color of each vertex reflects its elevation

I am currently developing an innovative audio analyzer, which can be found at this link: The analyzer is built using the technology of Three.js. Here is a snippet of the code: // Here goes your JavaScript code // It's quite lengthy, but it involv ...

React Hooks encountering issues with keydown/up events functionality

Currently, I am in the process of implementing arrow-based keyboard controls for a game that I have been developing. In order to stay updated with React, I decided to utilize function components and hooks. To showcase my progress, I have put together a dem ...

The dropdown menu disappears when I hover over the tab, making it impossible for me to navigate it in the react app

My navigation component includes a Games tab with a dropdown menu that appears when you hover over it. However, I'm facing an issue where the dropdown menu closes before the user can transition from hovering over the games tab to the actual dropdown m ...

Attempting to develop a Chrome Cordova application, however encountering the issue of navigator being undefined

I am currently working on developing a Chrome Cordova App, and while all the Chrome App APIs are functioning well, I am facing some challenges with more advanced features like capturing images or accessing accelerometer data. Despite my app running smooth ...

Numerous classifications and tags available for c3-angular-directive-c3 charts

I have a project requirement to create a stacked bar chart that should look like the image below: https://i.sstatic.net/MBwXy.png Currently, I am utilizing the c3-angular-directive library along with c3.js for chart creation. The challenge lies in dealin ...

Tips for adjusting the animation position in Off-Canvas Menu Effects

I am currently utilizing the wave menu effect from OffCanvasMenuEffects. You can view this menu in action below: ... // CSS code snippets here <link rel="stylesheet" type="text/css" href="https://tympanus.net/Development/OffCanvasMenuEffects/fonts/f ...

Testing an Angular service with dependencies on AngularJS services

I need help transitioning my angular js services to a new angular 7 app. The problem is, these services have dependencies on other angularjs services and I can't convert them all at once while still adding new features. How can I inject angular js ser ...

Revolving mechanism within React.js

I am currently developing a lottery application using React.js that features a spinning wheel in SVG format. Users can spin the wheel and it smoothly stops at a random position generated by my application. https://i.stack.imgur.com/I7oFb.png To use the w ...

How can I ensure that the state is only updated after the map function has finished executing in React?

I am encountering an issue with updating the state after mapping over an array of ids using an async function. The goal is to store the result in newArr and then update the state via setState. However, the state is being updated before the mapping operatio ...

Enhancing Angular 4 classes with dependency injection techniques

Currently utilizing angular 4 and angular cli for my project development. I have created some classes that serve as the base for my components! However, as the constructors of these classes grow during development, I find myself in a phase where I need to ...

I must be patient until the component is visible on the screen, says Protractor

Currently facing an issue where I have to wait for a component to appear on the screen, but sometimes it takes too long to load. Is there a way to wait until a specific field or variable becomes true? element(by.id('nextStage-button')).isPresent ...

The scrollbar will be visible only when the mouse hovers over the table

I have been experimenting with customizing the scrollbar appearance of an ant design table. Currently, the scrollbar always displays as shown in this demo: https://i.stack.imgur.com/vlEPB.png However, I am trying to achieve a scroll behavior where the sc ...

Activate hover effect on toggle button

When I hover over the "CHANGE" button, the orange color appears as expected. Clicking the button once turns the color red but removes the hover color, which is fine. However, clicking it twice brings back the original blue color but the hover effect is m ...

Utilize React Native to continuously fetch and display data from this API

[React-Native] Seeking assistance on looping through JSON API for conditional rendering. As a beginner, I would greatly appreciate your guidance. Thank you. Find my code here: https://drive.google.com/file/d/0B3x6OW2-ZXs6SGgxWmtFTFRHV00/view Check out th ...

I am utilizing jQuery's AJAX function with a datatype of HTML to extract a specific portion of the incoming data

This is the JavaScript function I am working with: function getCountryRegions() { var postData = "id="+$("#selectedCountryId").val(); $.ajax({ url:"/region", data: postData, dataType:"html", type:"POST", ...

performing various actions using jQuery ajax

I am looking for a way to carry out an operation and display the progress at the same time using HTML5 and JavaScript. With IE 8 not supporting the <progress> element, my alternative approach involves utilizing jQuery AJAX method as shown below: < ...

Generate a hard copy of the data table row without needing to view it beforehand

Here are some records from a table: +--------+---------+-------+----------+--------+ | Name | Address | Phone + Email | Action | +--------+---------+-------+----------+--------+ | Andy | NYC | 555 | <a href="/cdn-cgi/l/email-protection" cl ...

Updating documents in MongoDB periodically at specified intervals

I have developed a unique "lowest bid auction" system where users can set a base price, a price drop amount, and a price drop interval. For instance, if a user sets the base price as $1000, price drop amount as $100, and price drop interval as 1 hour, the ...