2017-08-30 52 views
1

我正在嘗試將Geolocation Ionic本地插件添加到我的Ionic 2.0應用程序中。Ionic 2.0 - 將插件添加到應用程序模塊 - 無效的語法?

按照說明書here,我已經導入了地理位置插件,我試圖將它添加到我的AppModule裝飾的'供應商的陣列,但我得到一個語法錯誤:

import { Geolocation } from '@ionic-native/geolocation'; 
... 

@NgModule({ 
    declarations: [ 
    MyApp, 
    BasketPage, 
    AccountPage, 
    AccountCreationPage, 
    CategoriesPage, 
    TabsPage, 
    LandingPage, 
    CategoryPage, 
    ProductPage 
    ], 
    imports: [ 
     IonicModule.forRoot(MyApp), 
     HttpModule 
    ], 
    bootstrap: [IonicApp], 
    entryComponents: [ 
    MyApp, 
    BasketPage, 
    AccountPage, 
    AccountCreationPage, 
    CategoriesPage, 
    TabsPage, 
    LandingPage, 
    CategoryPage, 
    ProductPage 
    ], 
    providers: [ 
     Geolocation, 
     { provide: ErrorHandler, useClass: IonicErrorHandler } 
    ] 
}) 
export class AppModule {} 

的providers數組似乎只接受具有'provide'和'useClass'屬性的對象,因此添加Geolocation對象不起作用。

此外,如果您檢查Ionic文檔,提供程序數組看起來與我的不同?這是爲什麼?當我查看Ionic文檔時,只有兩個版本 - v1和'latest'。

我在這裏做錯了什麼?

錯誤消息的任務運行是建立在應用程序如下:當我(雖然在紅語法錯誤Visual Studio的亮點反正):

12:56:37] typescript: …rce/Repos/Aise/Aise/AiseMobile/node_modules/@ionic-native/geolocation/index.d.ts, line: 127 Type ‘any’ is not a constructor function type. L127: export declare class Geolocation extends IonicNativePlugin {

僅供參考,這裏是從輸出離子信息命令:

cli packages: (C:\Users\ciara\Source\Repos\Aise\Aise\AiseMobile\node_modules)

@ionic/cli-utils : 1.9.2 ionic (Ionic CLI) : 3.9.2 global packages:

Cordova CLI : 7.0.1 local packages:

@ionic/app-scripts : 1.1.0 Cordova Platforms : android 6.2.3 Ionic Framework : ionic-angular 2.0.1 System:

Android SDK Tools : 25.2.3 Node : v6.10.3 npm
: 3.10.10 OS : Windows 10

的package.json

{ 
    "name": "io.cordova.myappeaf9db", 
    "author": "", 
    "homepage": "", 
    "private": true, 
    "scripts": { 
    "clean": "ionic-app-scripts clean", 
    "build": "ionic-app-scripts build", 
    "ionic:build": "ionic-app-scripts build", 
    "ionic:serve": "ionic-app-scripts serve", 
    "watch": "ionic-app-scripts watch" 
    }, 
    "dependencies": { 
    "@angular/common": "2.2.1", 
    "@angular/compiler": "2.2.1", 
    "@angular/compiler-cli": "2.2.1", 
    "@angular/core": "2.2.1", 
    "@angular/forms": "2.2.1", 
    "@angular/http": "2.2.1", 
    "@angular/platform-browser": "2.2.1", 
    "@angular/platform-browser-dynamic": "2.2.1", 
    "@angular/platform-server": "2.2.1", 
    "@ionic-native/geolocation": "^4.2.1", 
    "@ionic/storage": "1.1.7", 
    "cordova-android": "^6.2.3", 
    "cordova-plugin-compat": "^1.0.0", 
    "cordova-plugin-console": "1.0.5", 
    "cordova-plugin-device": "1.1.4", 
    "cordova-plugin-geolocation": "^2.4.3", 
    "cordova-plugin-splashscreen": "~4.0.1", 
    "cordova-plugin-statusbar": "2.2.1", 
    "cordova-plugin-whitelist": "1.3.1", 
    "ionic-angular": "2.0.1", 
    "ionic-native": "2.4.1", 
    "ionic-plugin-keyboard": "~2.2.1", 
    "ionicons": "3.0.0", 
    "jsonpath": "0.2.12", 
    "rxjs": "5.0.0-beta.12", 
    "sw-toolbox": "3.4.0", 
    "zone.js": "0.6.26" 
    }, 
    "devDependencies": { 
    "@ionic/app-scripts": "1.1.0", 
    "@ionic/cli-plugin-ionic-angular": "1.2.0", 
    "typescript": "2.0.9" 
    }, 
    "description": "Ionic2Tabs: An Ionic project", 
    "cordovaPlugins": [ 
    "cordova-plugin-whitelist", 
    "cordova-plugin-console", 
    "cordova-plugin-statusbar", 
    "cordova-plugin-device", 
    "cordova-plugin-splashscreen", 
    "ionic-plugin-keyboard" 
    ], 
    "cordovaPlatforms": [], 
    "-vs-binding": { 
    "BeforeBuild": [ 
     "ionic:build" 
    ], 
    "ProjectOpened": [ 
     "watch" 
    ] 
    }, 
    "cordova": { 
    "plugins": { 
     "cordova-plugin-console": {}, 
     "cordova-plugin-device": {}, 
     "cordova-plugin-splashscreen": {}, 
     "cordova-plugin-statusbar": {}, 
     "cordova-plugin-whitelist": {}, 
     "ionic-plugin-keyboard": {}, 
     "cordova-plugin-geolocation": {} 
    }, 
    "platforms": [ 
     "android" 
    ] 
    } 
} 
+1

什麼是語法錯誤信息? –

+0

我更新了原來的評論。謝謝。 –

+0

看起來像類似於https://stackoverflow.com/questions/43759991/ionic-3-type-any-is-not-a-constructor-function-type –

回答

1

如果你打算使用ionic-native 2.x,你不需要安裝ionic-native/<pluginName>包。

在2.x版本中,所有本地插件包裝都包含在單核心包中。所有插件類型均爲全球靜態

在你的情況下使用是

import { Geolocation } from ionic-native // import 

//To access the functions, 

Geolocation.functionName() 

您可以卸載ionic-native/Geolocation包。
您也不必在AppModule中設置提供程序或在構造函數中注入。

相關問題