Using $cordovaNetwork inside directive


#1

Hello, I written a simple directive like below.

thing is i am not able to access $cordovaNetwork inside directive controller. i lost scope of $cordovaNetwork the moment I am in link/contorller.I nver able hist $cordovaNetwork:online/offline events.

Any help?

angular.module("claimsApp").directive("notes", ["$window", "$rootScope", "$cordovaNetwork", "$ionicPopup", "$ionicPlatform", notes]);

function notes($window, $rootScope, $cordovaNetwork, $ionicPopup, $ionicPlatform) {

    var directive = {
        link: link,
        controller: controller,
        restrict: "EA",
        scope: {},
    };
    return directive;

    function init() {
        $ionicPlatform.ready(function () {
            if (window.Connection) {
                $rootScope.$on('$cordovaNetwork:online', function (event, networkState) {
                    console.log('online good sir');
                });
                $rootScope.$on('$cordovaNetwork:offline', function (event, networkState) {
                    console.log('offline good sir');
                });
            }
        });
    }

    

    function link($scope, $element, $attrs) {
      
        console.log("***inside link: " + $scope + "element: " + $element + "attrs: " + $attrs);
    }

    function controller($scope, $element, $attrs) {
           init();           
    }
}

})();`