Dynamic change the display of network status


#1

Hi, I am using https://github.com/apache/cordova-plugin-network-information for my ionic 1 APP.

It’s no problem to detect the network status. However, I got a problem is that when I changed the network from wifi to 4G. The status can’t be changed dynamic, it will still keep showing wifi in the view. May I know how to make the status change dynamic ?

Below is my code. Many thanks.

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}}
<!— it will show correctly at the first time, but when the network status change, it will not change. —>