InAppBrowser传递一个回调函数 [英] InAppBrowser passing a callback function

查看:186
本文介绍了InAppBrowser传递一个回调函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个InAppBrowser在我的应用程序工作正常。

  $ scope.openInAppBrowser =功能(URL){
        VAR REF = window.open(EN codeURI(URL),_blank,位置= YES');
        ref.addEventListener('loadstop',函数(事件){
            如果(event.url.match(亲密)){
                $ scope.refreshGamePage = 1; //这个变量是在手表的指示
                ref.close();
            }
        });
    }

下面是写入刷新页面指示

  module.directive('reloadPage',['$ HTTP',函数($ HTTP){
    返回{
        限制:'A',
        链接:功能($范围,元素,ATTRS){
             $ scope.refreshPage =功能(){
                如果($ scope.refreshGamePage == 1)
                    返回true;
                其他
                    返回false;
            };            $范围。$腕表($ scope.refreshPage,功能(五){
                如果(ⅴ){
                    $ scope.setGamePage(); //这个功能将包含code刷新网页游戏
                }
                });
            }
        };
    }]);

但似乎loadstop事件监听器是无法更新范围的变量。
谁能帮我这个?

基本想法是我想在我的应用程序,只要InAppBrowser关闭本身刷新当前页面(一个从InAppBrowser打开)。

没有更好的办法来实现,这将是AP preciated。


解决方案

  

只要使用角度$ apply()方法来改变角度值
  变量,因为它是改出来的angularjs转。


  $ scope.openInAppBrowser =功能(URL){
        VAR REF = window.open(EN codeURI(URL),_blank,位置= YES');
        ref.addEventListener('loadstop',函数(事件){
            如果(event.url.match(亲密)){
                $范围。$应用(函数(){
                $ scope.refreshGamePage = 1;
              });
                ref.close();
            }
        });
    }

I have a InAppBrowser working fine in my app

$scope.openInAppBrowser = function (url) {
        var ref = window.open(encodeURI(url), '_blank', 'location=yes');
        ref.addEventListener('loadstop', function (event) {
            if (event.url.match("close")) {
                $scope.refreshGamePage = 1; // this variable is under watch in a directive
                ref.close();
            }           
        });
    }

here is the directive written to refresh the page

module.directive('reloadPage', ['$http', function ($http) {
    return {
        restrict: 'A',
        link: function ($scope, element, attrs) {
             $scope.refreshPage = function () {
                if($scope.refreshGamePage ==1)
                    return true;
                else
                    return  false;
            };

            $scope.$watch($scope.refreshPage, function (v) {
                if (v) {
                    $scope.setGamePage(); // this function will contains code to refresh game page
                }
                });
            }       
        };
    }]);

but it seems like loadstop event listener is unable to update scope variable. Can anyone help me with this?

Basically idea is I want to refresh current page (one from which InAppBrowser opened) in my app as soon as InAppBrowser closes itself.

Any better way to achieve this will be appreciated.

解决方案

Just use angular $apply() method to change the value of angular variables because it is changed out of angularjs turn.

$scope.openInAppBrowser = function (url) {
        var ref = window.open(encodeURI(url), '_blank', 'location=yes');
        ref.addEventListener('loadstop', function (event) {
            if (event.url.match("close")) {
                $scope.$apply(function () {
                $scope.refreshGamePage = 1;
              });
                ref.close();
            }           
        });
    }

这篇关于InAppBrowser传递一个回调函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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