我有以下代码来在线/离线检查我的cordova应用程序。Cordova角度离线检查
var networkState = navigator.connection.type;
var states = {};
states[Connection.UNKNOWN] = 'Unknown';
states[Connection.ETHERNET] = 'Ethernet';
states[Connection.WIFI] = 'WiFi';
states[Connection.CELL_2G] = 'Cell2G';
states[Connection.CELL_3G] = 'Cell3G';
states[Connection.CELL_4G] = 'Cell4G';
states[Connection.CELL] = 'Cellgeneric';
states[Connection.NONE] = 'Nonetwork';
alert(states[networkState]);
if(states[networkState]!='Nonetwork'){
online=true;
}else{
online=false;
}
而我的角度控制器就像下面。
.controller('MainCtrl',['$scope','$http','$localStorage','$state',function($scope, $http, $localStorage, $state){
if(online==true){
//code for online
}else{
// code for offline
}
}])
我叫“deviceready”事件的检查,状态得到。但我的问题是 - deviceready
被称为后我控制器started.is可以检查网络状态前角控制器开始执行的?
在你的例子中,我看不到'deviceready'被调用的地方。可能会有一些元素缺失。你在哪里叫第一块代码检查网络? – sebastienbarbier