What is the process for moving information between files?

I have two files which are named as,

employee-rates-controller.ts:

private load() {

return this.entityService
      .load(this.$scope.projectRevisionUid)
      .then(resp => {
        localStorage.removeItem('employeerates');
        this.$scope.employeeRates = resp.employeeRates;
        return this.refreshCostRate(...resp.employeeRates)
          .then(() =>
            localStorage.setItem(
              'employeerates',
              JSON.stringify(this.$scope.employeeRates)
            )
          )
      .then(() => this.refreshBillRate(...resp.employeeRates))
      .then(() => resp.employeeRates.forEach(erm => this.calculate(erm)))
      .then(() => DatepickerUtil.reinitializeDatepickers(this.$scope));
      })

}

And in the other file,

getEmployeeRates.ts:

  const employeerates = JSON.parse(
    localStorage.getItem('employeerates')
  );

  if (employeerates && employeerates.length != null) {
    employeerates.forEach((element: any) => {
      if (
        this.employee.getUid() === element.user.personUid &&
        element.internalRate
      ) {
        this.cost_rate_uom = element.internalRate * this.uom_factor;
        this.cost_rate_per_hour =
          this.cost_rate_uom / this.uom_factor;
        this.cost_rate.setValue(this.ap4_cost_rate_per_hour);
      }
    });
  }

In one of the ts files, we have,

localStorage.setItem('employeerates',JSON.stringify(this.$scope.employeeRates))

And in the second ts file where we receive the data,

const employeerates = JSON.parse(localStorage.getItem('employeerates'));

While adding a few employees does not cause issues, adding a large number of employees and storing them into localstorage results in an error when the data size becomes too large, ultimately blocking the entire process.

The specific error encountered is as follows:

QuotaExceededError: Failed to execute 'setItem' on 'Storage': Setting the value of 'employeerates' exceeded the quota.

Hence, I am looking for a solution to transfer large data from one file to another without relying on local storage.

Since the application is built using the combination of Angularjs and Typescript, finding the right solution has been challenging due to my limited experience in this scenario.

Edit:

In addition to the first TS file, I can also fetch the value in this file.

employeeratemodel.ts:

export class EmployeeRateModel {
public uid: string;
.
.
.
public internalRate: number; // Accessing the value here
}

How can I retrieve this value inside the second ts file getEmployeeRates.ts:?..

My attempt so far:

import { EmployeeRateModel } from '../component/employee-rates/model/employee-rate.model';

constructor() {
    const data = new EmployeeRateModel();
    console.log(data) // {}  // The result is an empty object.. I need to extract the internalRate from it..
  }

If I can successfully retrieve the data, I will be able to access the internalRate required for calculations. However, since everything returns empty currently, this approach has not worked for me.

Please assist me in resolving this issue in the most appropriate manner, as I have been stuck on this problem for a while now.

Answer №1

Utilize the power of IndexedDB, a robust NoSQL storage system that allows you to store various data in the user's browser. It comes with a generous storage limit of approximately 20% of the total storage available on the client computer.

For Angular applications, consider using the NPM Package Angular IndexedDB.

Answer №2

Did you know that Chrome's Local Storage default size is 10 Mb? If your data exceeds this limit, clearing your Chrome's local storage could be the solution. Alternatively, consider storing your data on blob storage and accessing it directly from there.

If you encounter errors related to local storage being full, you can handle them with the following code snippet:

try {
     var counter = 1;
     var stringData = "AddLocalStorageTillItIsFull";
     for (var i = 0; i <= counter; counter + 1) {
         stringData += stringData;
         localStorage.setItem("localStorageData", stringData);
         console.log(stringData);
         console.log(counter);
     }

 }
 catch (e) {
     // When local storage is full, it goes hits this carch block
     console.log("Local Storage is full, Please clear local storage data to add more");
 }

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 create a sequential number pattern of 1, 2, 3, 4 in Mongoose?

Is there a way to create a similar pattern without coding experience? I'm not familiar with coding, so looking for guidance. Here is the code snippet in question: array = 1,2,3,4,5 const note = new notedModel ({ _id: array, note: args[1] ...

I'm new to Angular, so could you please explain this to me? I'm trying to understand the concept of `private todoItems: TodoItem[] = []`. I know `TodoItem` is an array that

//This pertains to the todoList class// The property name is todoItems, which is an array of TodoItem objects fetched from the TodoItem file. I am unable to make it private using "private todoItems: TodoItem[] = []," is this because of Dependency Injectio ...

"Enhance your web development skills by mastering jQuery alongside the

It's curious that jQuery doesn't support the use of the "+" sign. You can see how it functions with "1" and "3", but not with "2+". Just hover your mouse over each div to experience it. <div id="div-2+"></div> JSFiddle $('a. ...

Deactivate the Submit button when the database field has been populated

My form includes a submit button. The Submit button should be disabled if the "price" for a specific product is already filled: PHP Code <?php $host="localhost"; $username="root"; $password=""; $db_name="ge"; $con=mysqli_connect("$h ...

Data string not being converted correctly to date format

Here is a table I am currently working with: ID DateColumn 1 3/7/2019 5:29:38 AM 2 3/8/2019 5:28:38 AM 3 3/7/2019 5:30:38 AM 4 3/7/2019 5:31:38 AM The date column in this table is being processed as a string when bound to the grid. To ...

Exploring ways to assign a value to an HTML element utilizing Jquery in combination with ASP.NET MVC 4 complex model information

Within an ASP.NET MVC 4 view, I am utilizing data from a Model to populate various HTML elements. The model is used in the view to showcase values like: <div>@Model.Category.Name</div> etc... However, there is a specific div tag <div id="D ...

Is it possible for a submission of a form to modify the content length header, resulting in the request failing?

Issue Description: After binding a submit event to an AJAX post request in order to send a predetermined key-value pair to a PHP script, the expected message indicating successful communication is not received. Despite the fact that the submit event trig ...

Is there a reason for the absence of the Revit category attribute in the JSON response retrieved from the GET request :urn/metadata/:guid/

After receiving the information from the endpoint regarding Revit Models uploaded to my bucket, I noticed that the JSON response contains multiple objects. These objects seem to represent Revit elements, each with all parameters except for the Revit Categ ...

What is the best way for me to determine the average number of likes on a post?

I have a Post model with various fields such as author, content, views, likedBy, tags, and comments. model Post { createdAt DateTime @default(now()) updatedAt DateTime @updatedAt id String @id @default(cuid()) author U ...

Tips for setting a new key and value for an existing object in TypeScript

As I transition from JavaScript to TypeScript, I am currently working on creating a Discord bot using TypeScript to familiarize myself with the environment. However, I encountered an error when attempting to add new keys to an object that was previously cr ...

When TypeScript in IntelliJ fails to generate JavaScript files after enabling the tsconfig declaration

In my tsconfig file, I have the following setup: { "compilerOptions": { "module": "ESNext", "target": "es6", "sourceMap": true, "rootDir": "./&qu ...

Exploring Angular Testing with SpyOn

Apologies for my inexperience with Angular, but I am struggling with using spyOn in a unit test. In my unit test, there is a method on the component that calls service1, which in turn calls another service2. However, when I try to spyOn service1 in order ...

Error Encountered with Custom Ajax File Uploader's .AjaxSubmit() Function

I am working on a multipart form that allows users to upload images using AJAX. Here is the HTML code: <form name="mainform" id="mainform" class="form_step" action="" method="POST" enctype="multipart/form-data"> <!-- This image acts li ...

Accessing XML files locally via JavaScript on Chrome or Internet Explorer, with compatiblity for Android mobile devices as well

Looking to extract and display data from an XML file directly in an HTML page without the need for a web server. Ready to dive into using JavaScript, jQuery, or Ajax to get the job done. ...

Building a theme with TypeScript in React

As I embark on my React project, I've been tasked with creating a CSS using TypeScript while referring to the color palette diagram provided below. Utilizing createMuiTheme to build the theme, I've realized that there are various possible conditi ...

Remove the blue outline in Fancybox when clicked

Does anyone know how to remove the default blue outline that appears after opening and closing an image or video in Fancybox 3? It disappears when clicked next to, but I would like to get rid of it completely. Any help is appreciated. https://i.stack.imgu ...

Encountering TS 2732 error while attempting to incorporate JSON into Typescript

Having trouble importing a JSON file into my TypeScript program, I keep getting error TS2732: Can't find module. The JSON file I'm trying to import is located in the src folder alongside the main.ts file. Here's my code: import logs = requi ...

Encountering a Jasmine test issue on the Jenkins Build Server involving angular-mocks?

I'm currently conducting unit tests on an Angular directive using Angular and Jasmine. I have successfully mocked the http backend and all tests are running smoothly on my local machine. However, when running the tests on the build server, I encounter ...

Updating the state in React is causing significant delays

In my React project, I am utilizing the pdf-lib (JS library) for some intensive tasks using async/await. My goal is to update a progress bar by modifying the state. However, when I use setState within a setTimeout, the state changes are not reflected unt ...

Translating languages and localizing content

I am currently using angular-translate and it is working correctly. I have a select box for selecting the language. .config(['$translateProvider', function($translateProvider) { $translateProvider.translations('en', translationsEN) ...