所以我在我的移动应用程序中使用了Angular2和Ionic2。我的应用程序一直在编译和运行,直到我向应用程序添加了一个新模块以在谷歌地图中进行导航。我正在使用 phonegap-launch-navigator 来做到这一点。我导入模块的类是我的 Maps 类,该类的结构如下所示;
import { LaunchNavigator, LaunchNavigatorOptions} from 'ionic-native';
import { Component, NgZone } from "@angular/core";
import { NavController, Platform, NavParams } from 'ionic-angular';
import {GoogleMap, GoogleMapsEvent, GoogleMapsLatLng, GoogleMapsMarkerOptions, CameraPosition } from 'ionic-native';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import { Geolocation } from 'ionic-native';
import { Injectable,forwardRef,Inject } from "@angular/core";
@Component({
selector: 'maps-page',
templateUrl: 'maps.html',
})
export class MapsPage {
private map: GoogleMap;
destination:string;
start:string;
constructor(public LaunchNavigatorOptions: LaunchNavigatorOptions,
private _navController: NavController,
private LaunchNavigator:LaunchNavigator,
private platform: Platform,
public navCtrl: NavController,
public navParams: NavParams,
private _zone: NgZone) {
this.start = "";
this.destination = "Westminster, London, UK";
this.platform.ready().then(() => this.onPlatformReady());
}
我的包.json看起来像这样
{
"name": "ionic-hello-world",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"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",
"test": "mocha"
},
"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/cloud-angular": "^0.11.0",
"@ionic/storage": "1.1.7",
"angular2-jwt": "^0.1.28",
"bootstrap": "^3.3.7",
"ionic-angular": "2.0.0-rc.4",
"ionic-native": "2.2.11",
"ionicons": "3.0.0",
"jquery": "^3.1.1",
"moment": "^2.17.1",
"ng2-translate": "^5.0.0",
"rxjs": "5.0.0-beta.12",
"zone.js": "0.6.26"
},
"devDependencies": {
"@ionic/app-scripts": "^1.0.0",
"typescript": "2.0.9"
},
"cordovaPlugins": [
"cordova-plugin-whitelist",
"cordova-plugin-console",
"cordova-plugin-statusbar",
"cordova-plugin-device",
"cordova-plugin-splashscreen",
"ionic-plugin-keyboard"
],
"cordovaPlatforms": [
"ios",
{
"platform": "ios",
"version": "",
"locator": "ios"
}
],
"description": "myApp: An Ionic project"
}
导入这两个模块并将它们放入构造函数后,我什至无法启动我的应用程序,并且它给出了一个运行时错误,指出"无法解析 MapsPage(?,NavController,LaunchNavigator,Platform,NavController,NavParams,NgZone(的所有参数。我认为问题出在 LaunchNavigatorOptions 上,因为当我专门评论那个选项时,应用程序能够再次运行而不会出现任何问题。我能做些什么来让它工作吗?任何帮助,不胜感激。谢谢!
看起来您使用的是离子原生 v2.2.11。
在这个版本中,插件是全局的和静态的,不应该注入到构造函数中。只需删除
public LaunchNavigatorOptions: LaunchNavigatorOptions
和
private LaunchNavigator:LaunchNavigator,
从构造函数。
查看文档以升级到 Ionic-Native 3.x