Tips for transferring an array between two applications using AngularJS

I have two applications, appA for front end and appB for admin end.

In appA, I am building an array called queries using a service through a controller. However, when I try to retrieve this array list in a controller in appB, it appears empty.

Everytime appB is loaded, the page gets refreshed.

Here is the service I am using to store and share the array:

.factory('myService', function() {
    var queries = [];
    var factory = {};

    factory.addQuery = function(query) {
        queries.push(query);
        return queries;
    };
    factory.allQueries = function() {
        return queries;
    };
    return factory;
});

Application A

angular.module("appA", ['ui.router', ..)

Application B

angular.module("appB", ['ui.router', ..)

Can anyone assist me with this issue?

Answer №1

One simple solution is to utilize the power of localStorage.

For setting it up, you can use:

localStorage.setItem('queries', queriesVariable);

To retrieve data from another application:

localStorage.getItem('queries');

Or simply access it like this:

localStorage.queries;

If you don't require the data to persist beyond a page refresh, consider using sessionStorage.

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

Modify the paragraph's class upon clicking the radio button

I have been struggling with changing the color of <p> based on the radio button selected using two classes, red and blue. However, for some reason, it's not working as expected. If anyone has any insights or suggestions on how to fix this issue ...

Retrieve and modify the various elements belonging to a specific category

I'm currently developing a chrome extension and I need to access all elements of this specific type: https://i.stack.imgur.com/sDZSI.png I attempted the following but was unable to modify the CSS properties of these elements: const nodeList = documen ...

Stop the selection of text within rt tags (furigana)

I love incorporating ruby annotation to include furigana above Japanese characters: <ruby><rb>漢</rb><rt>かん</rt></ruby><ruby><rb>字</rb><rt>じ</rt></ruby> However, when attemp ...

Reverting back to PDF using jQuery

I am currently utilizing jQuery to send JSON data back to the server, which in turn generates a PDF report. However, I am facing an issue where the PDF is not downloading despite specifying the necessary response header and including JavaScript as shown ...

Creating JSON arrays for multiple elements using the same model name

I am using Angular to generate JSON data for multiple elements. Currently, the output looks like this: {"field":{"name":{"0":"a","1":"b"},"length":{"0":10,"1":20}}} However, I would like the JSON data to be more sophisticated and in array form, like this ...

Node.js and Express: tackling the problem of duplicate variables

I have a checkUser middleware that saves the user information when a JWT is verified. However, when I integrate it into my routes and attempt to log res.locals.user.username, the username appears twice in the console. This duplication is causing issues wit ...

Managing state with Apollo within a component

Greetings and thank you for taking the time to help me out. I am currently diving into the world of Apollo and React, but it seems like I am struggling with some logic here. On my main page index.js, I have initialized Apollo in the following way: export c ...

Design a div in the shape of a trapezium with clipped overflow

Is there a way to create a trapezium using CSS/Html/Canvas? I have attempted to do so, but my current method is messy and not practical. div { width:0; margin-left:-1000px; height:100px; border-right:1000px solid lightblue; border-top:60px solid tra ...

Organizing MVC5 with Angular JS: How to Create an Effective Folder Structure

As someone new to Angular and eager to learn best practices, I'm wondering about the ideal folder structure for an ASP.NET MVC5 AngularJS application. MVC5 default layout - Controllers Folder - Models Folder - Views Folder ---> Action Name Folder ...

Building an anchor tag that employs the HTTP DELETE method within an Express.js app

Recently, I delved into using express.js with handlebars.js as my template engine. One task I wanted to tackle was creating a delete link that followed RESTful principles and used the HTTP DELETE verb instead of GET. After some trial and error, I discover ...

What could be causing the submenus in my intricate menu component to lose focus when input is entered?

I'm currently working on developing a menu using the MUI Menu component. The goal is to have a popup input control (such as Autocomplete, TextField, Select, or a custom form) appear when a menu item is clicked, based on the choice made from the menu. ...

The file upload issue with FormData append in CodeIgniter is causing errors

My current challenge involves uploading files using AJAX to my CodeIgniter based website. Unfortunately, I am encountering an issue where I cannot retrieve the file field value in the controller. This results in an error message stating "Undefined index: & ...

Placing JavaScript at the bottom of the page, sourced from a Partial Page

I'm trying to display JavaScript code from a Razor Partial Page at the bottom of a (layout) Page. In a similar discussion on Stack Overflow about Including JavaScript at bottom of page, from Partial Views, it was suggested by user Becuzz that using a ...

Expanding Arrays in TypeScript for a particular type

There is a method to extend arrays for any type: declare global { interface Array<T> { remove(elem: T): Array<T>; } } if (!Array.prototype.remove) { Array.prototype.remove = function<T>(this: T[], elem: T): T[] { return thi ...

Refresh Ajax/Javascripts following the loading of new data with .html() function

My website has a page that utilizes an ajax function to load data into the page. The ajax function is as follows: $(document).ready(function(){ function loadData(page){ $.ajax ...

What is the best way to remove any objects in this array that have empty strings as values?

I have been developing a form using Angular 14. The form consists of a primary section, which includes the user's necessary information, and a secondary section where users can input additional data (an array of residences displayed in a table) befor ...

What is the method for accessing a marker from beyond the map on OpenStreetMap?

Recently, I made the switch from using Google Maps to OpenStreetMap in my project due to the request limit constraints imposed by Google. My client needed a higher request limit, but was unable to afford the costs associated with increasing it on Google Ma ...

The new Date function is malfunctioning on Firefox

Could you please explain why this particular function is not functioning correctly in Firefox (V 34 latest)? It appears to be working successfully on all other browsers, but 'DatePosted' is displaying as Invalid Date. Do you have any insights on ...

Utilizing Laravel to Showcase Google Maps with Custom Markers Generated from MySQL Data

As I work on developing a web application that involves integrating Google Maps and multiple markers, I encountered an issue this morning. Initially, I successfully implemented the map with markers from a single database table. However, my goal now is to ...

Unlocking keys of JavaScript class prior to class initialization

My constructor was becoming too large and difficult to maintain, so I came up with a solution to start refactoring it. However, even this new approach seemed bulky and prone to errors. constructor(data: Partial<BusinessConfiguration>) { if(!d ...