Need help with $rootscope and $cordovaNetwork

Hello, ive been working on an app for a while now with a few plugins added.
But the app cant function properly without connection, so i wanted to add the $cordovaNetwork

But here comes my problem all the sudden.
when i add the $cordovaNetwork or $rootscope to my controller i keep getting an Unknown provider
.controller('loginCtrl', ['$scope', '$state', '$ionicHistory', '$localstorage', '$http', 'Auth', 'Login', '$cordovaNetwork', function ($scope, $state, $ionicHistory, $localstorage, $http, Auth, Login, $cordovaNetwork) { .... }

Error: [$injector:unpr] Unknown provider: $cordovaNetworkProvider <- $cordovaNetwork <- loginCtrl

// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
// 'starter.controllers' is found in controllers.js
angular.module('starter', ['ionic', 'starter.controllers', 'starter.services'])

.factory('$localstorage', ['$window', function ($window) {
    return {
        set: function (key, value) {
            $window.localStorage[key] = value;
        },
        get: function (key, defaultValue) {
            return $window.localStorage[key] || defaultValue;
        },
        setObject: function (key, value) {
            $window.localStorage[key] = JSON.stringify(value);
        },
        getObject: function (key) {
            return JSON.parse($window.localStorage[key] || '{}');
        },
        removeObject: function (key) {
            $window.localStorage.removeItem(key);
        }
    }
}])

.run(function ($ionicPlatform) {
    if (window.StatusBar) {
        StatusBar.hide();
    }
    $ionicPlatform.ready(function () {
        // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
        // for form inputs)
        if (window.cordova && window.cordova.plugins.Keyboard) {
            cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
            cordova.plugins.Keyboard.disableScroll(true);

        }
        if (window.StatusBar) {
            StatusBar.hide();
        }

    });
})

.config(function ($stateProvider, $urlRouterProvider, $ionicConfigProvider) {
    $stateProvider
      .state('app', {
          url: '/app',
          abstract: true,
          templateUrl: 'templates/menu.html',
          controller: 'AppCtrl',
          onEnter: function ($state, Auth, Contacts) {
              if (!Auth.isLoggedIn()) {
                  $state.go('login');
              }
          }
      })
    .state('app.main', {
        url: '/main',
        views: {
            'menuContent': {
                templateUrl: 'templates/main.html',
                controller: 'mainCtrl'
            }
        }
    })
    .state('login', {
        url: '/login',
        templateUrl: "templates/login.html",
        controller: 'loginCtrl',
        onEnter: function ($state, Auth) {
            if (Auth.isLoggedIn()) {
                $state.go('app.main');
            }
        }
    });
    // if none of the above states are matched, use this as the fallback
    $urlRouterProvider.otherwise('login');

    $ionicConfigProvider.views.maxCache(0);
});

so please what am i doing wrong?

@mathiasRobinson

look at this solution

@nitishrajput01
Ive already seen that one, and I cant seem to figur out how i do this, ive just updated the question with my app.config and app.run, so please if you could show how it is supposed to be

@mathiasRobinson

did you injected ‘ngCordova’ in your module . Use Cordova Network Information plugin

and add below code before app.run . see if you are getting network information on console ?

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {

    console.log(navigator.network.connection.type);


}

@nitishrajput01
Ive just added the code, the console output is wifi.

about the ngCordova I’m not sure what is ment with this sorry. im still new with ionic app development
the first thread got my entire app.js
and ive used the cordova plugin add cordova-plugin-network-information

check for internet connection if it’s working or not

 if (navigator.network.connection.type == Connection.NONE) {
                    $ionicPopup.show({
                        title: '<h1 class="delete_popup">No Internet Connection !<br>',
                        template: '<h2 class="ceter_popup_text">You have no Internet Connection</h2>',
                        cssClass: 'custom-popup',
                        buttons: [{
                            text: 'Try Again',
                            onTap: function (e) {



                            }

        }, {
                            text: 'Cancel',
                            onTap: function (e) {

                                ionic.Platform.exitApp();


                            }
 }]


                });

thank you works great. Do this use the plugin or can i remove it again?

@mathiasRobinson

No don’t remove this plugin .whole working is depend on this plugin

okay, thank you very much.