我正在使用https://github.com/apache/cordova-plugin-network-information作为我的离子1 APP。
检测网络状态没有问题。但是,我遇到的一个问题是,当我将网络从wifi改为4G时。状态无法动态更改,它仍会在视图中显示wifi。我可以知道如何使状态变化动态吗?
以下是我的代码。非常感谢。
controller.js
.controller(‘NetworkCtrl', function($scope) {
var networkState = navigator.connection.type;
var states = {};
states[Connection.UNKNOWN] = 'Unknown connection';
states[Connection.ETHERNET] = 'Ethernet connection';
states[Connection.WIFI] = 'WiFi connection';
states[Connection.CELL_2G] = 'Cell 2G connection';
states[Connection.CELL_3G] = 'Cell 3G connection';
states[Connection.CELL_4G] = 'Cell 4G connection';
states[Connection.CELL] = 'Cell generic connection';
states[Connection.NONE] = 'No network connection';
$scope.networkstatus = states[networkState];
})
Network.html
{{networkstatus}}