Ped*_*edo 2 ionic-framework angular
尝试在我的离子应用程序中使用存储版本 2.1.3 但出现错误:
NullInjectorError: R3InjectorError(AppModule)[AppModule -> Storage -> Storage -> Storage]: NullInjectorError: No provider for Storage! ionic 6
Run Code Online (Sandbox Code Playgroud)
我看到一些关于它的帖子,告诉我们使用 forRoot 语句,但无论如何都不起作用。
我的应用程序模块:
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();
}
}
Run Code Online (Sandbox Code Playgroud)
如果有任何其他信息可能有帮助,请询问,我会提供。谢谢!
您没有Storage从任何地方导入构造函数;它应该从以下位置导入:
import { Storage } from '@ionic/storage';
Run Code Online (Sandbox Code Playgroud)
否则它可能会导入 typescript 的 Web Storage API 接口。
| 归档时间: |
|
| 查看次数: |
8269 次 |
| 最近记录: |