问题描述
我尝试使用cordova pluguin InAppBrowser在我的应用程序远程地址中打开。我使用该代码:
I trying to open in my app remote address using cordova pluguin InAppBrowser. I use that code:
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:无法读取未定义的属性'addEventListener'
And I get an Error on 'loadstart' event:TypeError: Cannot read property 'addEventListener' on undefined
我认为一切都很好。但它会引发错误吗?我做错了什么?
我使用这个插件
I think that all is allright. But it fire the error? What I'm doing wrong?I use this pluguin https://ionicframework.com/docs/v2/native/inappbrowser/
并在模拟器和Android 6版本的设备上进行测试。一样的问题。
在config.xml中我使用该代码:
And test it on emulator and on device with Android 6 version. The same problem.In config.xml I use that code:
<allow-navigation href="*://192.168.1.2/*"/>
我使用最新的Ionic 2.2.1版本。
And I use the lastest Ionic 2.2.1 version.
推荐答案
问题是我做的在使用该类之前不要安装pluguin。
The problem was that I'm do not install pluguin before use the class.
ionic plugin add cordova-plugin-inappbrowser
这篇关于TypeError:无法在未定义的Angular2,Ionic 2,InAppBrowser上读取属性'addEventListener'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!