简体   繁体   English

如何进行Ionic InAppBrowser集成?

[英]How can I make Ionic InAppBrowser integration?

I am beginner at angular JS and ionic framework! 我是有角JS和离子框架的初学者! I need to integrate a static web page inside my app using InAppBrowser; 我需要使用InAppBrowser将静态网页集成到我的应用程序中; I tried to insert the code in home.ts file but I don't know what to write in home.html file!! 我试图在home.ts文件中插入代码,但是我不知道在home.html文件中写什么! All I need the functionality of opening predefined webpage inside home.ts that appears as soon as I press home button in tab theme. 我只需要在home.ts内打开预定义网页的功能,该功能在我按选项卡主题中的“主页”按钮后即会出现。 I would be grateful If some one helped me. 如果有人帮助我,我将不胜感激。

You don't need to include anything in your html-file. 您无需在html文件中包含任何内容。 Only if you want to open the static webpage using a button in your app. 仅当您想使用应用程序中的按钮打开静态网页时。

Just include plugin and the function in your home.ts-file with: 只需在您的home.ts文件中包含插件和函数即可:

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

and add the InAppBrowser to your constructor like this: 并将InAppBrowser添加到您的构造函数中,如下所示:

constructor(private iab: InAppBrowser) { }

and finally declare your function with: 最后声明您的功能:

openBrowser(){
  const browser = this.iab.create('https://ionicframework.com/');
}

If you would like to open the static webpage at the startup of the app just add the openBrowser-Function to the ionViewDidLoad-Function which is being executed every loading the Home-Page. 如果您想在应用程序启动时打开静态网页,只需将openBrowser-Function添加到ionViewDidLoad-Function即可,每次加载主页时都会执行该功能。

ionViewDidLoad(){
  this.openBrowser();
}

so your final home.ts should look like this: 因此您的最终home.ts应该如下所示:

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

export class HomePage {
  constructor(private iab: InAppBrowser) {}

  ionViewDidLoad(){
    this.openBrowser();
  }

  openBrowser(){
    const browser = this.iab.create('https://ionicframework.com/');
  }

}

For more information check the plugin documentation: click 有关更多信息,请查看插件文档: 单击

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM