Ionic storage is unable to assign a number as a string

My goal is to store all numbers retrieved from the function getWarrentsNumber() in ionic storage, but I encountered an error.

Error: The argument of type "number" cannot be assigned to type 'string'.

this.storage.set(this.NumberOfAssignedWarrents, 'LOCAL STORAGE NUMBER');
    this.storage.get('name').then((name) => {
      console.log('Me: Hey, ' + name + '! You have a very nice name.');
      console.log('You: Thanks! I got it for my birthday.');
    });
  },
  error => {

  }
  );

This function retrieves the number of tasks from the database:

getWarrentsNumber() {

    let id = localStorage.getItem('userId');

    this.peopleProvider.getAllWorkerAssignedWarrents(id).toPromise()
      .then(result => {
        this.NumberOfAssignedWarrents = result.length;
        localStorage.setItem('DodNalog', result);
      });
    this.peopleProvider.getAllWorkerFinishedWarrents(id).toPromise()
      .then(result => {
        this.NumberOfFinishedWarrents = result.length;
        localStorage.setItem('ZavNalog', result);
      });
    this.peopleProvider.getAllWorkerUnfinishedWarrents(id).toPromise()
      .then(result => {
        this.NumberOfUnfinishedWarrents = result.length;
        localStorage.setItem('NezavNalog', result);
        console.log(result);
      });
  }

Answer №1

An error occurs on this line because the key is being set as a number, which is not allowed according to the Ionic documentation. The first parameter (key) should be a string.

this.storage.set(this.NumberOfAssignedWarrents, 'LOCAL STORAGE BROJ');

To resolve this issue, the code should be modified to:

this.storage.set('LOCAL STORAGE BROJ',this.NumberOfAssignedWarrents);

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

Dealing With HttpClient and Asynchronous Functionality in Angular

I've been pondering this issue all day. I have a button that should withdraw a student from a class, which is straightforward. However, it should also check the database for a waiting list for that class and enroll the next person if there is any. In ...

Creating a new tab with the same html template binding in Angular 4

Could a button be created that, when clicked, opens a new browser tab featuring the same component and variables declared previously? <label>Please Enter Your Email Below</label> <input name="userEmail" type="text" class="form-control" re ...

Customizing Material UI CSS in Angular: A Guide

Recently, while working with the Mat-grid-tile tag, I noticed that it utilizes a css class called .mat-grid-tile-content, which you can see below. The issue I am encountering is that the content within the mat-grid-tile tag appears centered, rather than f ...

Navigating resolvedUrl with getServerSideProps in the newest version of NextJS - a comprehensive guide

Is there a way to obtain the pathname without using client-side rendering? I have been searching for information on how to utilize the getServerSideProps function, but so far with no luck. Initially, I attempted to employ usePathname; however, this result ...

Tips for adjusting the color of the snackbar in Angular

When a user logs out, I am using snackBar to display a message. I want to change the color of the panel from dark grey to another color and tried using the following solution: panelClass: ['danger'] supposed to change the panel color to red ( ...

What is the reason behind Angular's repeat filter only being able to access its own element within the return function?

I have successfully implemented some Angular code that is working, however, I am struggling to understand why it works. Coming from a C Sharp background and being new to JS and Typescript. <tr ng-repeat="colleague in Model.FilteredColleagueListModel | ...

Firebase and Angular 7 encountered a CORS policy block while trying to access an image from the origin

I am attempting to convert images that are stored in Firebase storage into base64 strings in order to use them in offline mode with my Angular 7/Ionic 4 application! (I am using AngularFire2) However, I encountered an error message stating: Access to i ...

Converting JSON to TypeScript with Angular Casting

I'm facing an issue detailed below. API: "Data": [ { "Id": 90110, "Name": "John", "Surname": "Doe", "Email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="472d282f2923282207202a262e2b ...

When the back button is pressed on android, the navbar does not immediately refresh the active class

When using a webapp on Chrome for Android, pressing the back button results in double active items in the navbar. Clicking outside of the navbar removes the old active item. I attempted to resolve the issue by adding [routerLinkActiveOptions]="{ exact: tr ...

Struggling with transitioning from TypeScript to React when implementing react-data-grid 7.0.0

I'm trying to add drag and drop functionality to my React project using react-data-grid, but I keep encountering a "TypeError: Object(...) is not a function" error. I have a TypeScript version of the file in the sandbox as a reference, but when I try ...

Could you please tell me the type that is returned by the createClient function?

Despite being a TS newbie, I have been delving into writing small services using TS. Recently, I've been developing a CLI tool that leverages the power of node-redis, which is an exceptional redis client. The burning question on my mind is regarding ...

Angular BehaviorSubject is failing to emit the next value

I am facing an issue with a service that uses a Behavior subject which is not triggering the next() function. Upon checking, I can see that the method is being called as the response is logged in the console. errorSubject = new BehaviorSubject<any> ...

Should one bother utilizing Promise.all within the context of a TypeORM transaction?

Using TypeORM to perform two operations in a single transaction with no specified order. Will utilizing Promise.all result in faster processing, or do the commands wait internally regardless? Is there any discernible difference in efficiency between the t ...

What are the steps to effectively implement the useEffect hook in React?

I'm facing an issue where I am trying to return a function that utilizes useEffect from a custom usehook, but I keep getting the error "useEffect is called in a function which is neither a react function component nor a custom hook." Here's what ...

Ways to mimic an Angular subscription during a Jasmine test

I'm currently troubleshooting a unit test for my code (I'm not very experienced with Jasmine) after adding some subscriptions to a service. I'm encountering an issue where the subscriptions are coming up as undefined. I'm not entirely s ...

The system could not find the command "tsc" as an internal or external command, or as an operable program or script file

I'm new to using type script and I'm having trouble compiling my files. When I press Ctrl+Shift+B in VS Code, I receive the error message "tsc is not recognized." I installed typescript using npm. C:\Users\sramesh>npm install -g t ...

How to Retrieve ViewChild Element from within Input Component in Angular 2

Currently, I am utilizing ViewChild to target a specific HTML element within an Angular 2 component. My goal is to access this element from an Input field, but I am struggling with the correct syntax to correctly target the element in question. Below is th ...

What is the method for extracting individual elements from an object returned by a React hook in Typescript?

I am currently working on a component that needs access to the query parameters from React Router. To achieve this, I have been using the use-react-router hook package in my project. This is what I am trying to accomplish: import React from "react; impor ...

The variable is currently undefined because it has an array assigned to it

Upon selecting multiple checkboxes for variants, I am retrieving checked data using the following method: get selectedIdsFromViolCategoriesFormArray(): string[] { return this.violCategories .filter((cat, catIdx) => this.violCategoriesFormArr. ...

Unlocking the Power of the .data Attribute in Angular's In-Memory Web API

My objective is to seamlessly switch between using in-memory-web-api and a real backend. In the Angular 2 (or 4) Tour of Heroes tutorial, it explains how the server returns data. The in-memory web API example returns an object with a 'data' prop ...