CordovaNetwork not beeing detected by angular controller

Viewed 101

I've a little problem with CordovaNetwork plugin on an IONIC v1.x application.

I've installed it with a

sudo cordova plugin add cordova-plugin-network-information

Injected the plugin into an angular controller

.controller('HomeCtrl',function($cordovaNetwork)...

Testing it doing

console.log($cordovaNetwork.isOnline());

And i'm getting this error:

$cordovaNetwork.isOnline() is not a function

I've already removed/installed the plugin. The same thing with the IOS platform. And my cordova files include are like this:

<!-- cordova script (this will be a 404 during development) -->
    <script src="lib/ngCordova/dist/ng-cordova.js"></script>
    <script src="cordova.js"></script>

What am i doing wrong? Thank you a lot!

2 Answers

Place your code inside device ready event:

   document.addEventListener("deviceready", function () {

    var isOnline = $cordovaNetwork.isOnline(); 
    var isOffline = $cordovaNetwork.isOffline();

  }, false);

I found what was causing the error.

I just forgot to add 'ngCordova.plugins.network' into my app.js injections.

Related