ionic-team / ionic-team/ionic-storage

ERROR Error: Uncaught (in promise): NullInjectorError: R3InjectorError(AppModule)[AuthGuard -> StorageService -> Storage -> Storage]: NullInjectorError: No provider for Storage!

Aperta
#308 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
TypeScript
Stelle
456
Fork
97
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

hey i'm facing this error
```
ERROR Error: Uncaught (in promise): NullInjectorError: R3InjectorError(AppModule)[AuthGuard -> StorageService -> Storage -> Storage]:
NullInjectorError: No provider for Storage!
NullInjectorError: R3InjectorError(AppModule)[AuthGuard -> StorageService -> Storage -> Storage]:
NullInjectorError: No provider for Storage!
at NullInjector.get (core.mjs:8771:27)
at R3Injector.get (core.mjs:9200:33)
at R3Injector.get (core.mjs:9200:33)
at injectInjectorOnly (core.mjs:652:33)
```

here is the service i have created
````
import { Injectable } from '@angular/core';

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

@Injectable({
providedIn: 'root'
})
export class StorageService {
private _storage: Storage;

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;
this._storage.set('isAdmin',false);
this._storage.set('token','');
}

// 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 get(key: string){
return this._storage?.get(key);
}
}
````

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Start with the shown StorageService constructor and the AppModule configuration, then trace how AuthGuard resolves StorageService. Reproduce the reported AuthGuard path and verify that the Storage dependency is registered and the NullInjectorError no longer occurs.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
angular, typescript
Ambito
frontend
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.