本地存储离子2错误 [英] Local storage in ionic 2 error

查看:78
本文介绍了本地存储离子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 version 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:

来自:从'@ ionic / storage'导入{Storage};

到: import来自'@ ionic / storage'的{IonicStorageModule};

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

Add the following to the imports array:

IonicStorageModule.forRoot()

导入数组应如下所示:

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





注意:不要对任何其他文件中的存储导入进行任何更改。

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

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

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