After login i want to set the user id into the local storage

After login i want to set the user id into the local can i do that? please help me

have you even checked the docs?

import { Storage } from '@ionic/storage';
constructor(public storage: Storage)
  setUserId() {'userId', this.userId);

@FnnHuman.i will check.

@FnnHuman where called the function setUserId() ?

if you ask me that you should learn how to code first

1 Like

@FnnHuman how to get the userId from the storage?'userId').then((val) => {

@FnnHuman Thank you.

@FnnHuman when i use the code an try to show userid in alert box.but showing the full. function error

what the hell, show me your code

below my service provider code
import { Injectable } from ‘@angular/core’;

import { Events } from ‘ionic-angular’;
import { Storage } from ‘@ionic/storage’;

export class UserData {
constructor(public events: Events,public storage: Storage) {}
setUserId(userid: string): void {‘userid’, userid);

getUserid() {
// Notice that the get method returns a promise!‘userid’).then((value) => {
/setUserId(): Promise {
return‘userid’).then((value) => {
return value;

from login.ts try to store userid into the local storage.

No it doesn’t. Your comment is a lie. That method doesn’t return anything, and if you used proper return type declarations instead of false comments, you would have gotten a build-time error informing you of this fact. Please read the TypeScript, Angular, and Ionic documentation thoroughly until you really understand the fundamental building blocks of web apps. You cannot become competent at this by simply copying random nonsense you see on the web and expecting reliable results.

@rapropos sorry for that.

@rapropos can i upload my full code?

I don’t intend it as a personal attack, but in order for other people in forums like this to be able to give you assistance in a productive manner, you need to build up core competence in your craft, assuming that you really have a passion for programming.

@rapropos Thanks for you valuable advice.