After login i want to set the user id into the local storage.how can i do that? please help me
have you even checked the docs?
import { Storage } from '@ionic/storage';
constructor(public storage: Storage)
setUserId() {
this.storage.set('userId', this.userId);
}
@FnnHuman.i will check.
if you ask me that you should learn how to code first
this.storage.get('userId').then((val) => {
console.log(val);
});
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’;
@Injectable()
export class UserData {
constructor(public events: Events,public storage: Storage) {}
setUserId(userid: string): void {
this.storage.set(‘userid’, userid);
};
getUserid() {
// Notice that the get method returns a promise!
this.storage.get(‘userid’).then((value) => {
//console.log(userid);
});
}
/setUserId(): Promise {
return this.storage.get(‘userid’).then((value) => {
return value;
});
};
};/
}
//this.userData.setUserId(this.setUserId);
from login.ts try to store userid into the local storage.
this.userData.setUserId(this.userid);
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.
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.