ionic 2 错误中的本地存储

Local storage in ionic 2 error(ionic 2 错误中的本地存储)
本文介绍了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 错误中的本地存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Android release APK crash with java.lang.AssertionError: impossible in java.lang.Enum(Android 发布 APK 因 java.lang.AssertionError 崩溃:在 java.lang.Enum 中不可能)
Finished with Non Zero Exit Value 3(以非零退出值 3 结束)
On gradle:3.0.0 More than one file was found with OS independent path #39;META-INF/ASL2.0#39;(在 gradle:3.0.0 上找到多个文件,其独立于操作系统的路径为“META-INF/ASL2.0)
Android : app loading library at runtime on Lollipop but not IceCreamSandwich(Android:运行时在 Lollipop 上而不是 IceCreamSandwich 上的应用程序加载库)
buildConfigField depending on flavor + buildType(buildConfigField 取决于风味 + buildType)
How do I suppress warnings when compiling an android library with gradle?(使用 gradle 编译 android 库时如何抑制警告?)