gpt4 book ai didi

javascript - AngularJS 中的 Phonegap ondeviceready 事件

转载 作者:行者123 更新时间:2023-12-03 10:15:12 25 4
gpt4 key购买 nike

您好,我正在使用 AngularJS 创建一个 PhoneGap 应用程序。这是我的 Controller :

module.controller('MainController', function($scope, $window, $rootScope){
$scope.funda="new Funda";
$scope.deviceReady = false;
document.addEventListener("deviceready", onDeviceReady, false);

console.log('mainCtrl is loaded');

function onOnline(){
alert('device is in online mode'); //cannot reach here
$rootScope.online = true;
$scope.online = $rootScope.online;
}
function onOffline(){
alert('device is not ready');
$rootScope.online = false;
$scope.online = $rootScope.online;
}

function onDeviceReady() {
$scope.$apply(function() {
alert('device is ready'); //Its Reaching here fine
document.addEventListener("online", onOnline, false);
document.addEventListener("offline", onOffline, false);
$scope.deviceReady = true;
});
}
});

看起来onDeviceReady这个函数触发得很好,但之后我可以到达onOnline函数。

是否还有其他方法可以调用angularjs中的deviceready函数。

谢谢!

最佳答案

我自己找到的答案。这很容易。 Angular 有自己的方法来解决这个问题。这是您只需要做的事情。

function onDeviceReady() {
alert(navigator.network.connection.type);
}

这将告诉您连接类型。

关于javascript - AngularJS 中的 Phonegap ondeviceready 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29915128/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com