ionic 2 - inappbrowser “browser.on(…).subscribe is not a function” error

删除回忆录丶 提交于 2019-12-22 05:17:23

问题


I follow this http://ionicframework.com/docs/native/in-app-browser/ document for use inappbrowser and try with below steps :

1- install

ionic cordova plugin add cordova-plugin-inappbrowser 

 npm install --save @ionic-native/in-app-browser

2 - Add this plugin to app.module.ts provider

3 - add to constructor :

constructor(private iab: InAppBrowser) { }

4- and use it in launch method like this :

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

launch(urlc){
      let url = 'https://example.com/';
      let browser = this.iab.create(url, '_blank', 'location=yes');
      browser.on('loadstart').subscribe((ev: InAppBrowserEvent) => {
          this.close_status=true;
      });
  }

but when serve and call launch method I see this error :

Runtime Error
browser.on(...).subscribe is not a function

回答1:


InAppBrowser is a cordova plugin, and because of that, it's not available when running the app in the browser with ionic serve.

Try to run the app on a simulator / real device to use the plugin.




回答2:


If you want to avoid this error you have 3 options:

  1. Run the app in a real device.
  2. Run the app in an emulator.
  3. Run the app in a browser, using the "Browser" platform (which is supported by the InAppBrowser plugin). Instead of doing:

    ionic serve

do:

ionic cordova run browser


来源:https://stackoverflow.com/questions/44328762/ionic-2-inappbrowser-browser-on-subscribe-is-not-a-function-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!