问题
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:
- Run the app in a real device.
- Run the app in an emulator.
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