离子2科尔多瓦InAppBrowser browser.close()不是函数 [英] Ionic 2 cordova InAppBrowser browser.close() is not a function

查看:92
本文介绍了离子2科尔多瓦InAppBrowser browser.close()不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的Ionic应用程序中集成了一个支付网关,其中我在服务器端使用Node JS.在单击按钮时,我使用ionic native inAppBrowser将用户重定向到付款网关页面,此后我正在监听url事件.付款成功后,浏览器将重定向到成功URL,否则它将重定向到失败URL.基于此,我正在处理应用程序中的UI.我的问题是,当我听成功/失败的URL并调用关闭浏览器事件时,出现此错误.

未捕获的TypeError:this.browser.close不是函数

我也尝试了hide()方法,但是遇到了同样的错误. 以下是我的代码.

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Http } from '@angular/http';
import { InAppBrowser, InAppBrowserEvent } from '@ionic-native/in-app-browser';
@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  event : any;
  browser:any;
  failed : boolean = false;
  success : boolean = false;
  constructor(public navCtrl: NavController, private http: Http,private iab: InAppBrowser) {

  }

  payment(){
    this.browser = this.iab.create('http://192.168.0.59:3000/post').on("loadstop")
     .subscribe((ev: InAppBrowserEvent) => {

              if(ev.url == "http://192.168.0.59:3000/failure"){
                console.log("payment failed");
                this.failed = true;
                this.closeBrowser();
              }else if(ev.url == "http://192.168.0.59:3000/success"){
                console.log("payment success");
                this.success = true;
              }

          });

      }

      closeBrowser(){
        this.browser.close();
      }

    }

我也在真实设备上测试该应用程序,因此没有任何cordova或平台问题...请告诉我我犯了什么错误. 正确答案的描述将对以后的参考很有帮助.

解决方案

尝试在构造函数中添加以下行:

this.browser = this.iab.create('http://192.168.0.59:3000/post');

您也可以将const用于此目的,例如:

const browser = this.iab.create('http://192.168.0.59:3000/post');

然后,使用付款方式

this.browser.on("loadstop")
.subscribe((ev: InAppBrowserEvent) => {
    // check conditions according to logic
});

如果在构造函数中使用const browser,则可以简单地使用browser.on().然后在closeBrowser()方法中,this.browser.close();将起作用.

检查 官方文档

I am integrating a payment gateway in my ionic app in which i am using node js on the server side. On a click of button i am redirecting user to the payment gateway page using ionic native inAppBrowser after which i am listening to url events. When the payment is successful then the browser will redirect to success url else it will redirect to failed url. Based on this i am handling the UI in the app. My problem is when i listen to the success/failed url and call the close browser event i get this error.

Uncaught TypeError: this.browser.close is not a function

I have also tried hide() method but i get the same error. Following is my code.

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Http } from '@angular/http';
import { InAppBrowser, InAppBrowserEvent } from '@ionic-native/in-app-browser';
@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  event : any;
  browser:any;
  failed : boolean = false;
  success : boolean = false;
  constructor(public navCtrl: NavController, private http: Http,private iab: InAppBrowser) {

  }

  payment(){
    this.browser = this.iab.create('http://192.168.0.59:3000/post').on("loadstop")
     .subscribe((ev: InAppBrowserEvent) => {

              if(ev.url == "http://192.168.0.59:3000/failure"){
                console.log("payment failed");
                this.failed = true;
                this.closeBrowser();
              }else if(ev.url == "http://192.168.0.59:3000/success"){
                console.log("payment success");
                this.success = true;
              }

          });

      }

      closeBrowser(){
        this.browser.close();
      }

    }

I am also testing the app on a real device so there isn't any cordova or platform issue...Please tell me what mistake i am making. A proper description with the answer will be quite helpful for my future references.

解决方案

Try adding following line inside constructor:

this.browser = this.iab.create('http://192.168.0.59:3000/post');

You can also use const for that purpose like:

const browser = this.iab.create('http://192.168.0.59:3000/post');

Then, in payment method just do

this.browser.on("loadstop")
.subscribe((ev: InAppBrowserEvent) => {
    // check conditions according to logic
});

You can simply use browser.on() if using const browser in constructor. And then in closeBrowser() method, this.browser.close(); will work.

Check Official Documentation

这篇关于离子2科尔多瓦InAppBrowser browser.close()不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆