ionic-team / ionic-team/ionic-storage

Method get is not working

Open
#313 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
456
Forks
97
PR merge metrics
No merged PRs in 30d

Description

Hello.

I'm using "@ionic/storage-angular": "^4.0.0" on the project. But, the method get return undefined.

```
import { Injectable } from '@angular/core';
import { Storage } from '@ionic/storage-angular';

@Injectable({
providedIn: 'root'
})
export class StorageService {

private _storage: Storage | null = null;

constructor(private storage: Storage) {
this.init();
}

async init() {
// If using, define drivers here: await this.storage.defineDriver(/*...*/);
const storage = await this.storage.create();
this._storage = storage;
}

// Create and expose methods that users of this service can
// call, for example:
public set(key: string, value: any) {
this._storage?.set(key, value);
}

public async get(key: string): Promise {
console.log(key);

const data = await this._storage?.get(key);
console.log(data);
return data;
}
}

```

The console shows:
login
storage.service.ts:31 undefined

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.