How to open a page so if you have internet connection?

I created a controller to check the type of connection, but wanted to attribute it to a link, for example when we click on the User menu, open it only if you have internet connection, if you have no connection it shows a warning … . sorry, I’m new with angular and without some javascript

//    cordova
.controller('cordovaDeviceCtrl', function ($scope) {
    $scope.device = device;
    $scope.connection = navigator.connection.type;
    $scope.states = {};
    $scope.states[Connection.NONE] = 'Check your internet connection';