Issue
Trying to use the storage version 2.1.3 in my ionic application but getting the error:
NullInjectorError: R3InjectorError(AppModule)[AppModule -> Storage -> Storage -> Storage]: NullInjectorError: No provider for Storage! ionic 6
I saw some posts about it, telling to use the forRoot statement, but didn't work anyway.
My appModule:
import { NgModule, OnInit } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { IonicStorageModule } from '@ionic/storage'
import {HttpClientModule} from '@angular/common/http'
@NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [BrowserModule, HttpClientModule, IonicModule.forRoot(), IonicStorageModule.forRoot(), AppRoutingModule], providers: [{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }],
bootstrap: [AppComponent],
})
export class AppModule implements OnInit {
constructor(private storage: Storage) { }
async ngOnInit() {
await this.storage.create();
}
}
If there is any other information that could be helpful just ask and I will provide it. Thanks!
Solution
You aren't importing the Storage
in your constructor from anywhere; it should be imported from:
import { Storage } from '@ionic/storage';
It's probably importing the Web Storage API interface of typescript otherwise.
Answered By - eko
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.