找不到名称“ ScreenOrientation”。离子屏幕方向插件错误

时间:2018-09-13 12:07:26

标签: ionic-framework angular6

我正在使用Angular 6使用离子版本4创建应用程序!我需要获取设备的方向,因此我使用了Ionic 4文档中的屏幕方向插件: [https://beta.ionicframework.com/docs/native/screen-orientation]

但是当我安装插件时,我得到的警告为:

.8.0-rc.1 but none is installed. You must install peer dependencies yourself.
npm WARN @ionic/ng-toolkit@1.0.8 requires a peer of @angular-devkit/build-angular@~0.8.0-rc.1 but none is installed. You must install peer dependencies yourself.
npm WARN @ionic/ng-toolkit@1.0.8 requires a peer of @angular-devkit/core@~0.8.0-rc.1 but none is installed. You must install peer dependencies yourself.
npm WARN @ionic/ng-toolkit@1.0.8 requires a peer of @angular-devkit/schematics@~0.8.0-rc.1 but none is installed. You must install peer dependencies yourself.
npm WARN @ionic/schematics-angular@1.0.6 requires a peer of @angular-devkit/core@~0.8.0-rc.1 but none is installed. You must install peer dependencies yourself.
npm WARN @ionic/schematics-angular@1.0.6 requires a peer of @angular-devkit/schematics@~0.8.0-rc.1 but none is installed. You must install peer dependencies yourself.
npm WARN @ionic-native/screen-orientation@4.12.2 requires a peer of @ionic-native/core@^4.11.0 but none is installed. You must install peer dependencies yourself.
npm WARN @ionic-native/screen-orientation@4.12.2 requires a peer of rxjs@^5.5.11 but none is installed. You must install peer dependencies yourself.

+ @ionic-native/screen-orientation@4.12.2
added 1 package in 8.608s

现在,当我尝试导入类似以下的页面时:

  

无法编译。

     

./ node_modules/@ionic-native/screen-orientation/index.js模块不   找到:错误:无法解析“ rxjs / Observable”   '/ Users / karthikcp / Documents / IONIC / testbake / node_modules / @ ionic-native / screen-orientation'

我该如何解决?

信息:

```
Ionic:

   ionic (Ionic CLI)          : 4.1.2 (/usr/local/lib/node_modules/ionic)
   Ionic Framework            : @ionic/angular 4.0.0-beta.7
   @angular-devkit/core       : 0.7.5
   @angular-devkit/schematics : 0.7.5
   @angular/cli               : 6.1.5
   @ionic/ng-toolkit          : 1.0.8
   @ionic/schematics-angular  : 1.0.6

Cordova:

   cordova (Cordova CLI) : 7.1.0
   Cordova Platforms     : none
   Cordova Plugins       : no whitelisted plugins (2 plugins total)

System:

   ios-deploy : 1.9.2
   NodeJS     : v8.11.3 (/Users/karthikcp/.nvm/versions/node/v8.11.3/bin/node)
   npm        : 5.6.0
   OS         : macOS High Sierra
   Xcode      : Xcode 9.4.1 Build version 9F2000

更新

我将插件重新安装为:npm install --save @ionic-native/screen-orientation@5.0.0-beta.15

现在我收到此错误:

  

src / app / pages / test / test.page.ts(14,42)中的错误:错误TS2304:找不到名称“ ScreenOrientation”。

依赖项:

"dependencies": {
    "@angular/common": "~6.1.1",
    "@angular/core": "~6.1.1",
    "@angular/forms": "~6.1.1",
    "@angular/http": "~6.1.1",
    "@angular/platform-browser": "~6.1.1",
    "@angular/platform-browser-dynamic": "~6.1.1",
    "@angular/router": "~6.1.1",
    "@ionic-native/core": "5.0.0-beta.15",
    "@ionic-native/screen-orientation": "^5.0.0-beta.15",
    "@ionic-native/splash-screen": "5.0.0-beta.15",
    "@ionic-native/status-bar": "5.0.0-beta.15",
    "@ionic/angular": "4.0.0-beta.7",
    "cordova-plugin-screen-orientation": "^3.0.1",
    "core-js": "^2.5.3",
    "rxjs": "6.2.2",
    "zone.js": "^0.8.26"
  },

2 个答案:

答案 0 :(得分:2)

如果我这样输入,我只会收到此错误:

import { ScreenOrientation } from '@ionic-native/screen-orientation';

但是如果我将/ngx添加到@ionic-native/screen-orientation,则不会显示找不到名称错误。 但是在我这边显示的是

NullInjectorError: No Provider for ScreenOrientation!

如果添加/ ngx,也许该工作就如所愿。

答案 1 :(得分:0)

这对我有用。在您的page.module内部,导入依赖项:

import { ScreenOrientation } from '@ionic-native/screen-orientation/ngx';

并提供给模块:

providers: [
    ScreenOrientation, 
    ...]

请注意,如果未从特定的导入中获得“ ScreenOrientation”的认可,它将采用打字稿界面。那是我的错误。