【发布时间】:2017-06-24 20:06:11
【问题描述】:
我尝试使用 Cordova 插件 InAppBrowser 在我的应用程序远程地址中打开。我使用该代码:
import { Injectable } from "@angular/core";
import { HttpQueryService } from "./httpqueryservice";
import { ToastController } from "ionic-angular";
import { InAppBrowser, InAppBrowserEvent } from "ionic-native";
/**
* Класс сервиса для открытия окон в браузере
*/
@Injectable()
export class WindowOpenService {
inAppBrowserRef: InAppBrowser; //объект с браузером
/**
* Конструктор класса
*/
constructor(
public toastCtrl: ToastController,
public httpQueryService: HttpQueryService
){
}
/**
* Open url in InAppBrowser
*
* @param url
* @param target
* @param options
*/
open(url = 'http://192.168.1.2/myurl/', target = '_blank', options = 'location=yes,hidden=no,hardwareback=yes,toolbar=yes')
{
try{
var inAppBrowserRef = new InAppBrowser(url, target, options);
inAppBrowserRef.on('loadstart').subscribe((result) => {
alert(result);
inAppBrowserRef.close();
});
inAppBrowserRef.on('mychange').subscribe((result) => {
alert(result);
this.inAppBrowserRef.close();
});
inAppBrowserRef.on('loadstop').subscribe((result) => {
alert(result);
this.inAppBrowserRef.close();
});
inAppBrowserRef.on('loaderror').subscribe((result) => {
alert(result);
inAppBrowserRef.close();
});
}catch(e){
alert(e);
}
}
}
我在 'loadstart' 事件中得到一个错误: TypeError: Cannot read property 'addEventListener' on undefined
我认为一切都很好。但它会引发错误吗?我做错了什么? 我用这个插件https://ionicframework.com/docs/v2/native/inappbrowser/
并在模拟器和 Android 6 版本的设备上进行测试。同样的问题。 在 config.xml 我使用该代码:
<allow-navigation href="*://192.168.1.2/*"/>
我使用的是最新的 Ionic 2.2.1 版本。
【问题讨论】:
-
我遇到了同样的问题,但我也安装了 cordova 插件。我仍然有同样的问题。我不断收到同样的错误。我已经分享了我正在使用的代码here。希望你能帮助我,因为我已经被困了好几天了。
-
您使用的是最新版本的 Ionic 2 吗?
-
是的,我正在使用最新的 Ionic 版本
2.2.1。
标签: angular ionic2 typeerror addeventlistener inappbrowser