javascript - 如何停止onHardwareBackButton的回调函数? ionic

标签 javascript android cordova ionic-framework

抱歉,如果我的英语一点也不完美。

我使用 $ionicPlatform.onHardwareBackButton 与屏幕方向插件一起使用,当您在播放 Youtube 视频时从 View 返回时,将方向更改为纵向,这是我正在做的示例:

app.controller('nameCtrl', ['$ionicPlatform', function('$ionicPlatform') {

    $scope.openVideo = function(id) {
        var isVideoPlaying = true;

        // some stuff here

        if(isVideoPlaying) {
            $ionicPlatform.onHardwareBackButton(function() {
                screen.lockOrientation('portrait');
                isVideoPlaying = false;
                alert('going back');
            });
        } // in this line i get an error "TypeError: object is not a function" from GapDebug
    }

}]);

onHardwareBackButton 检测工作完美,但是当我不播放视频时,也会调用回调函数。不知道为什么不能使用 bool 部分。有什么帮助吗?抱歉,这是一个愚蠢的问题。

我尝试在基于 GapDebug 的错误行中使用分号,但没有任何结果。

提前致谢

最佳答案

尝试这样的事情:

app.controller('nameCtrl', ['$ionicPlatform', function('$ionicPlatform') {

    $scope.openVideo = function(id) {
        var isVideoPlaying = true;

        // some stuff here
        $ionicPlatform.onHardwareBackButton(function() {

            if(isVideoPlaying) {
                screen.lockOrientation('portrait');
                isVideoPlaying = false;
                alert('going back');
            } // in this line i get an error "TypeError: object is not a function" from GapDebug
        });

    }

}]);

关于javascript - 如何停止onHardwareBackButton的回调函数? ionic ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28753071/

相关文章:

android - 如果使用 webview 完成身份验证,如何使用 Intent 过滤器处理 OAuth URL 回调?

javascript - Sproutcore + PhoneGap/钛?

javascript - Cordova/HTML 5 中的地理定位与 Meteor 地理定位包有何区别?

javascript - 拖动应用phonegap

javascript - jQuery - 使用复选框附加更改

javascript - 使用 jQuery draggable 将元素拖到可滚动的 div 之外

javascript - 如何在 jQuery 中为关键字解析文本?

android - 如果另一个任务依赖于第一个任务运行,Gradle任务不会删除文件

android - 更改设置 Android 后重新加载或重新创建旧 Activity

javascript - 如何为数据库中的不同记录/行创建用户生成的链接列表,单击后填充 html 表单?