I need assistance with persisting and sharing array data var queries = [];
between two separate AngularJS applications. One application is for the front end, while the other is for the admin side. Both applications cause the entire page to load when accessed.
I attempted to use the code below to share the data, but unfortunately, it's not working as expected:
.factory('QueryService', function() {
var queries = [];
var factory = {};
//..
factory.addQuery = function(query) {
queries.push(query);
localStorage.setItem('queries', JSON.stringify(queries));
console.log(JSON.parse(localStorage.getItem('queries')));
return JSON.parse(localStorage.getItem('queries'));
};
//..
return factory;
}
The above code only retrieves the last element added to the queries
array.
I also tried using angular-local-storage, but encountered the same issue.
.factory('QueryService', ['localStorageService', function(localStorageService) {
var queries = [];
var factory = {};
//..
factory.addQuery = function(query) {
queries.push(query);
localStorageService.set('queries', queries);
console.log(localStorageService.get(('queries')));
return localStorageService.get(('queries'));
};
//..
return factory;
}
I require the array queries
data to be accessible in both the front end and admin applications.
Can anyone provide guidance on how to achieve this?