ionic 2 错误中的本地存储 [英] Local storage in ionic 2 error

查看:16
本文介绍了ionic 2 错误中的本地存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在我的 Ionic 2 应用程序中使用它:https://ionicframework.com/docs/v2/storage/

I try to use this in my Ionic 2 application : https://ionicframework.com/docs/v2/storage/

我已经跑了

cordova plugin add cordova-sqlite-storage --save

npm install --save @ionic/storage

成功了.

当我尝试在我的 app.module.ts 中添加存储时,我遇到了这个错误:

And when I tried to add Storage in my app.module.ts, I had this error :

Error: Can't resolve all parameters for Storage: (?).
    at v (http://localhost:8100/build/polyfills.js:3:4864)
    at SyntaxError.BaseError [as constructor] (http://localhost:8100/build/main.js:127193:27)
    at new SyntaxError (http://localhost:8100/build/main.js:11660:16)
    at CompileMetadataResolver._getDependenciesMetadata (http://localhost:8100/build/main.js:27183:31)
    at CompileMetadataResolver._getTypeMetadata (http://localhost:8100/build/main.js:27058:26)
    at CompileMetadataResolver._getInjectableMetadata (http://localhost:8100/build/main.js:27046:21)
    at CompileMetadataResolver.getProviderMetadata (http://localhost:8100/build/main.js:27288:40)
    at http://localhost:8100/build/main.js:27246:49
    at Array.forEach (native)
    at CompileMetadataResolver._getProvidersMetadata (http://localhost:8100/build/main.js:27213:19)
    at CompileMetadataResolver.getNgModuleMetadata (http://localhost:8100/build/main.js:26897:50)
    at JitCompiler._loadModules (http://localhost:8100/build/main.js:72991:64)
    at JitCompiler._compileModuleAndComponents (http://localhost:8100/build/main.js:72951:52)
    at JitCompiler.compileModuleAsync (http://localhost:8100/build/main.js:72917:21)
    at PlatformRef_._bootstrapModuleWithZone (http://localhost:8100/build/main.js:52753:25)

我不明白我该怎么做才能解决它.

I don't understand how I have to do to solve it.

我的 app.module.ts :

My app.module.ts :

import { Storage } from '@ionic/storage';
...

providers: [
    {provide: ErrorHandler, useClass: IonicErrorHandler},
    PData,
    PBackground,
    PTranslate,
    Storage
  ]

...

推荐答案

从Ionic 2.2.0开始,推荐使用@ionic/storage 2.0.0版本.app.modules.ts 中的配置自上一个版本以来发生了变化.如果您没有以正确的方式更改所有内容,则会发生错误.

Since Ionic 2.2.0, it's recommended to use @ionic/storage version 2.0.0. Configuration in app.modules.ts has changed since the previous version. The error occurs if you haven't changed everything in the right way.

在 app.modules.ts 中进行以下更改:

In app.modules.ts do following changes:

  1. 从提供商处移除存储
  2. 更改导入语句:

  1. Remove Storage from providers
  2. Change import statement:

from: import { Storage } from '@ionic/storage';

到:import { IonicStorageModule } from '@ionic/storage';

将以下内容添加到导入数组中:

Add the following to the imports array:

IonicStorageModule.forRoot()

导入数组应如下所示:

imports: [
  IonicModule.forRoot(MyApp),
  IonicStorageModule.forRoot()
],



注意:请勿对任何其他文件中的 Storage 导入进行任何更改.

NOTE: Do not make any change in imports of Storage in any other files.

这篇关于ionic 2 错误中的本地存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆