任何人都可以为Ionic 2框架提供InAppBrowser示例应用程序吗?

时间:2016-09-27 20:51:19

标签: ionic-framework ionic2

任何人都可以提供InAppBrowser示例应用吗?我是Ionic 2的新手,我无法让它运转起来。

import {Component} from '@angular/core';
import { Slides } from 'ionic-angular';
import {InAppBrowser} from 'ionic-native';

@Component({
  templateUrl: 'build/pages/hello-ionic/hello-ionic.html'
})
export class HelloIonicPage {

  constructor() {
 }

openBrowser(){
let browser = new InAppBrowser('https://ionic.io', '_system');
}

}
<ion-header>
  <ion-navbar>
    <button menuToggle>
      <ion-icon name="menu"></ion-icon>
    </button>
    <ion-title>Hello Ionic</ion-title>
  </ion-navbar>
</ion-header>

<ion-content class="content">
<button (click)="openBrowser()">Open Browser</button>

</ion-content>

这会引发以下错误:

TypeScript error: C:/Users/Chirag Jagga/IonicFinal/app/pages/hello-ionic/hello-ionic.ts(14,15): Error TS2346: Supplied parameters do not match any signature of call target.

取自:http://ionicframework.com/docs/v2/native/inappbrowser/

1 个答案:

答案 0 :(得分:2)

试试这个:

import { Component} from '@angular/core';
import { NavController} from 'ionic-angular';
import { InAppBrowser} from '@ionic-native/in-app-browser'


@Component({
  selector: 'hello',
  templateUrl: 'templateUrl: 'build/pages/hello-ionic/hello-ionic.html'})


export class HelloIonicPage {

  constructor(private iab: InAppBrowser) { }


openBrowser(){
  const browser = this.iab.create('https://ionic.io', '_system' );
   browser.close();
 }
}

确保在您的应用模块提供者中添加“InAppBrowser”作为提供者:

import { InAppBrowser} from '@ionic-native/in-app-browser'


@NgModule({
  . . .
  . . .
providers: [..,InAppBrowser,...]
})

在此处查看:https://matthiasomisore.com/index.php/2017/06/01/ionic2-using-inappbrowser-to-load-a-web-browser/