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

Swift: Comparing the functions of addingObjects method versus the append method

I'm in the process of learning Swift 3 for iOS development and I was curious about the distinction between these two methods: if let myItemArray = itemObject as? NSArray { myItemArray.addingObjects(from: [itemTextField.text!]) ...

Ways to clear an individual form field using element-ui

I'm currently learning VueJS and incorporating the Element-UI framework into my project. One issue I'm facing is that when there's a validation error upon submitting the login form, I'd like to automatically clear the password field. A ...

Creating new form fields dynamically using JavaScript (triggered by onClick event)

I want to dynamically add fields based on user interaction. For instance, when the checkbox or radio button is clicked, additional fields like buttons and textfields should appear. Is it possible to achieve this using onClick? If so, can you please provide ...

Exploring the streamlined process of verifying a user's ability to connect using Slim in a RESTful

I have a unique situation where my SLim API is integrated into my ANgularJS application to interact with the database like so (for instance): Sample controller code: $scope.testDatabaseItems = function(){ $http.get(pathApi + 'items').succes ...

Error alert: The system could not locate Google when trying to drop pins

Every time I attempt to place pins on the map, I encounter the "google is not defined" error. The map itself displays without any issues until I add the lines following the initMap() function. I have come across similar posts but none of the suggested so ...

Could you explain the distinction between these two arrow functions?

I'm puzzled about why the second arrow function is effective while the first one isn't. //the first one doesn't function properly this.setState = () => { text: e.target.value, }; //in contrast, this one ...

Navigating through objects to retrieve internal object values

I currently have a collection of objects stored in my program. const objs = { "1":{ "name":"Candice", "Classes": [00029,00023,00032,000222], "id":0002918 }, "2":{ "name":"Clark", "classes" ...

Can the data from these JSON elements be obtained?

Suppose I have a JSON file with the following structure: { "update" : { "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c3a6aea2aaaf83a4aea2aaafeda0acae">[email protected]</a>":{ "1234": {"notfication" ...

Angular error TS2531: Object may be null

Within my Component.html file, I have an input field set up like this: <input type="text" (change) = "setNewUserName($event.target.value)"/> The code within the component.ts file looks like this: import { Component } from "@ ...

Executing numerous Ajax requests within a single Rails view

Two ajax requests are being used on a single page, one showcasing a date and the other displaying a calendar. The first request updates the date upon clicking a date on the calendar. The second request allows for switching between months on the calendar. ...

Draggable vue includes a Textarea HTML element that allows users to easily

The issue lies in implementing the draggable functionality on a textarea element. While the textarea allows text input and deletion, trying to select the text using pointer events triggers the dragging function instead, as shown in the image below: https ...

Enhance data granularity in Jquery Flot by zooming in as the user interacts

I'm currently working on creating an interactive chart that allows users to zoom in for a more detailed view of the data. For instance, when viewing data over a default zoom period of 3 months, there would be one data point displayed every 24 hours. H ...

There are currently no articles found that match the search query

Recently, I started working with Django, but I am facing an issue with slug. Whenever I send a request to the Slug, I encounter an error. The error message I receive is: Articles matching query does not exist. Furthermore, I am facing another error while ...

Create a PHP form that includes a dropdown menu for selecting the quantity, allowing users to insert multiple rows of data inputted into the form

My first time posting something here. The issue I'm facing is: I have an HTML form with various variables. A dropdown for Quantity that should insert the data into a MySQL table multiple times based on the chosen quantity. For example, if the dropd ...

Learn the process of uploading an image to Firebase storage from the server side

I'm working on implementing an upload feature that utilizes Firebase storage on the server side. Here is the upload function on the server side: const functions = require("firebase-functions"); const admin = require("firebase-admin&quo ...

What is the process of creating a model instance in a Nodejs controller?

Trying to work with the model object in Node using the sequelize module. It looks something like this: File structure: models index.js user.js controllers userController.js routes route.js ========================== models/users.js //created us ...

Having difficulty implementing infinite-scroll functionality with angular-meteor collection filtering

Currently, I am in the process of developing a dynamic photo database that allows users to browse through photos, apply filters by user, select multiple categories of interest, and sort the filtered data based on different criteria such as date or number o ...

Why does my console refuse to log the input entered for the search?

Looking to become proficient in web development, I am attempting to record HTML search queries in the console after storing them in a variable. However, when I try running the search procedure, nothing seems to be displaying in my browser's inspect co ...

Why is there a discrepancy between the value displayed in a console.log on keydown and the value assigned to an object?

As I type into a text box and log the keydown event in Chrome, I notice that it has various properties (specifically, I'm interested in accessing KeyboardEvent.code). Console Log Output { altKey: false bubbles: true cancelBubble: false cancelable: t ...

Tips on eliminating overlapping strokes

I'm having trouble with drawing an array of circles that are meant to intersect a series of lines. The issue I face is that if the circles overlap, a stroke appears underneath them which I want to remove. Does anyone have any suggestions on how to el ...