Ionic3:无法声明 InAppBrowser
Ionic3: Cannot declare InAppBrowser
我想使用 InAppBrowser 打开所有 目标空白 链接。我遵循文档,在构造函数上声明插件时总是出错:
Can't resolve all parameters for MyApp: (?, ?, ?).
当我将 private iab: InAppBrowser
放在构造函数上时出现此错误。
我的代码:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { InAppBrowser } from '@ionic-native/in-app-browser';
import { Platform } from 'ionic-angular';
@Component({
selector: 'page-home',
templateUrl: 'home.html',
})
export class HomePage {
constructor(public navCtrl: NavController, public plt: Platform, private iab: InAppBrowser) {
this.plt.ready().then((readySource) => {
console.log("Ready!");
window.open = this.iab.open;
});
}
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { InAppBrowser } from '@ionic-native/in-app-browser';
@NgModule({
declarations: [
MyApp,
HomePage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage
],
providers: [
StatusBar,
SplashScreen,
InAppBrowser,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
export class AppModule {}
有人知道它是什么吗?
谢谢!
您的代码看起来不错,所以问题似乎是因为您的项目使用的 @ionic-native/core
版本。
如您所见in the docs Ionic 团队更新了 Ionic Native 命令以避免此错误:
Installation
To add Ionic Native to your app, run following command to install the core package:
npm install @ionic-native/core@4 --save
还有...
Usage
Install the Needed Plugins
Install the Ionic Native package for each plugin you want to add.
For example, if you want to install the Camera plugin, you will need to run the following command:
npm install @ionic-native/camera@4 --save
Then install the plugin using Cordova or Ionic CLI. For example:
ionic cordova plugin add cordova-plugin-camera
注意两个命令中的 @4。这允许您安装正确版本的 Ionic Native 依赖项,即使您使用的是新的 CLI。
TLDR; 因此,如果您使用 @4 安装插件,您可以像这样导入它:import { InAppBrowser } from '@ionic-native/in-app-browser';
如果没有,您可能正在使用更新版本的 Ionic Native,因此您需要像这样导入它:import { InAppBrowser } from '@ionic-native/in-app-browser/ngx'
我想使用 InAppBrowser 打开所有 目标空白 链接。我遵循文档,在构造函数上声明插件时总是出错:
Can't resolve all parameters for MyApp: (?, ?, ?).
当我将 private iab: InAppBrowser
放在构造函数上时出现此错误。
我的代码:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { InAppBrowser } from '@ionic-native/in-app-browser';
import { Platform } from 'ionic-angular';
@Component({
selector: 'page-home',
templateUrl: 'home.html',
})
export class HomePage {
constructor(public navCtrl: NavController, public plt: Platform, private iab: InAppBrowser) {
this.plt.ready().then((readySource) => {
console.log("Ready!");
window.open = this.iab.open;
});
}
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { InAppBrowser } from '@ionic-native/in-app-browser';
@NgModule({
declarations: [
MyApp,
HomePage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage
],
providers: [
StatusBar,
SplashScreen,
InAppBrowser,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
export class AppModule {}
有人知道它是什么吗?
谢谢!
您的代码看起来不错,所以问题似乎是因为您的项目使用的 @ionic-native/core
版本。
如您所见in the docs Ionic 团队更新了 Ionic Native 命令以避免此错误:
Installation
To add Ionic Native to your app, run following command to install the core package:
npm install @ionic-native/core@4 --save
还有...
Usage
Install the Needed Plugins Install the Ionic Native package for each plugin you want to add. For example, if you want to install the Camera plugin, you will need to run the following command:
npm install @ionic-native/camera@4 --save
Then install the plugin using Cordova or Ionic CLI. For example:
ionic cordova plugin add cordova-plugin-camera
注意两个命令中的 @4。这允许您安装正确版本的 Ionic Native 依赖项,即使您使用的是新的 CLI。
TLDR; 因此,如果您使用 @4 安装插件,您可以像这样导入它:import { InAppBrowser } from '@ionic-native/in-app-browser';
如果没有,您可能正在使用更新版本的 Ionic Native,因此您需要像这样导入它:import { InAppBrowser } from '@ionic-native/in-app-browser/ngx'