Ionic 2 - 错误:没有Native Storage的提供程序

时间:2017-05-23 11:05:05

标签: ionic2

我正在使用Ionic documentation中指定的Native Storage插件,但是当我在设备或模拟器上部署时,我得到一个白色屏幕。当我将它连接到chrome后进一步检查>远程设备>检查。在控制台中我收到此错误错误错误:没有NativeStorage的提供程序!

任何指针?请帮忙

下面是我的错误日志:

NativeStorage!
    at Error (native)
    at injectionError (file:///android_asset/www/build/main.js:1509:86)
    at noProviderError (file:///android_asset/www/build/main.js:1547:12)
    at ReflectiveInjector_._throwOrNull (file:///android_asset/www/build/main.js:3048:19)
    at ReflectiveInjector_._getByKeyDefault (file:///android_asset/www/build/main.js:3087:25)
    at ReflectiveInjector_._getByKey (file:///android_asset/www/build/main.js:3019:25)
    at ReflectiveInjector_.get (file:///android_asset/www/build/main.js:2888:21)
    at NgModuleInjector.get (file:///android_asset/www/build/main.js:3835:52)
    at resolveDep (file:///android_asset/www/build/main.js:11202:45)
    at createClass (file:///android_asset/www/build/main.js:11071:32)View_MyApp_Host_0 @ ng:///AppModule/MyApp_Host.ngfactory.js:6

这是我的版本信息:

cordova CLI: 6.5.0
Ionic Framework Version: 3.2.1
Ionic CLI Version: 2.2.3
Ionic App Lib Version: 2.2.1
Ionic App Scripts Version: 1.3.7
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Windows 10
Node Version: v6.10.0
Xcode version: Not installed

的package.json

 {
  "name": "cccccccc",
  "version": "0.0.1",
  "author": "Ionic Framework",
  "homepage": "http://ionicframework.com/",
  "private": true,
  "scripts": {
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "lint": "ionic-app-scripts lint",
    "ionic:build": "ionic-app-scripts build",
    "ionic:serve": "ionic-app-scripts serve"
  },
  "dependencies": {
    "@angular/common": "4.1.0",
    "@angular/compiler": "4.1.0",
    "@angular/compiler-cli": "4.1.0",
    "@angular/core": "4.1.0",
    "@angular/forms": "4.1.0",
    "@angular/http": "4.1.0",
    "@angular/platform-browser": "4.1.0",
    "@angular/platform-browser-dynamic": "4.1.0",
    "@ionic-native/core": "3.7.0",
    "@ionic-native/facebook": "^3.10.2",
    "@ionic-native/native-storage": "^3.10.3",
    "@ionic-native/splash-screen": "3.7.0",
    "@ionic-native/status-bar": "3.7.0",
    "@ionic/storage": "2.0.1",
    "cordova-android": "^6.2.3",
    "cordova-plugin-console": "^1.0.5",
    "cordova-plugin-device": "^1.1.4",
    "cordova-plugin-facebook4": "^1.9.0",
    "cordova-plugin-splashscreen": "^4.0.3",
    "cordova-plugin-statusbar": "^2.2.2",
    "cordova-plugin-whitelist": "^1.3.1",
    "cordova-plugin-nativestorage":"^2.2.2",
    "ionic-angular": "3.2.1",
    "ionic-native": "^2.5.1",
    "ionic-plugin-keyboard": "^2.2.1",
    "ionicons": "3.0.0",
    "rxjs": "5.1.1",
    "sw-toolbox": "3.6.0",
    "zone.js": "0.8.10"
  },
  "devDependencies": {
    "@ionic/app-scripts": "1.3.7",
    "@ionic/cli-plugin-cordova": "1.1.2",
    "@ionic/cli-plugin-ionic-angular": "1.1.2",
    "typescript": "2.2.1"
  },
  "description": "An Ionic project",
  "cordova": {
    "plugins": {
      "cordova-plugin-console": {},
      "cordova-plugin-device": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-statusbar": {},
      "cordova-plugin-whitelist": {},
      "ionic-plugin-keyboard": {},
      "cordova-plugin-facebook4": {
        "APP_ID": "3xxxxxxxxxx2",
        "APP_NAME": "cxxxxxxe"
      }
    },
    "platforms": [
      "android"
    ]
  }
}

4 个答案:

答案 0 :(得分:6)

这是吗?

1)将您的nativestorage插件导入apps.module.ts:

import { NativeStorage } from '@ionic-native/native-storage';

2)将Provider设置为:

providers: [
  NativeStorage ,
  {provide: }
  ]

希望它会有所帮助

答案 1 :(得分:1)

删除条目:

 "ionic-native": "^2.5.1",

因为它是离子 - 天然3.x不需要的较老的离子 - 天然

同时尝试使用与@ionic-native/native-storage相同的@ionic-native/core版本。

"@ionic-native/native-storage": "3.7.0"

答案 2 :(得分:1)

首先感谢所有的回复,@ Suraj我在你提到之后检查了package.json,我必须在依赖项下手动添加"cordova-plugin-nativestorage":"^2.2.2",然后干净并构建。现在它可以在Device和Emulator上正常工作。非常感谢你提起这件事!!

答案 3 :(得分:1)

    在工作模块中
  1. 导入 NativeStorage 如下:

import { NativeStorage } from '@ionic-native/native-storage/ngx';

  1. 将其添加到提供者,如下所示:

    providers: [NativeStorage]

完整示例services.module.ts


import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { NativeStorage } from '@ionic-native/native-storage/ngx';
import { NativeStorageService } from './native-storage/native-storage.service';

@NgModule({
  declarations: [],
  imports: [
    CommonModule
  ],
  providers: [NativeStorage, NativeStorageService] 
})
export class ServicesModule { }