Home > angularjs > Ionic: trouble using ngCordova to check online/offline status

Ionic: trouble using ngCordova to check online/offline status

March 11Hits:2
Advertisement

I'm using ngCordova "Network Information" plugin to get the online/offline status of the host device. I have followed this tutorial (which excellent, as are his other posts):

Josh Morony - Monitoring Online and Offline States in an Ionic Application

I have implemented the "ConnectivityMonitor" service as described in the article.

In one of my controllers/templates it works perfectly:

(function() { 'use strict';  angular     .module('myApp')     .controller('ResearchController', ResearchController);  ResearchController.$inject = ['$scope', '$stateParams', 'MyApi', 'ConnectivityMonitor'];   function ResearchController($scope, $stateParams, MyApi, ConnectivityMonitor) { var vm = this;  vm.isOnline = ConnectivityMonitor.isOnline();  ... }    <ion-view title="RESEARCH" ng-controller="ResearchController as vm" >     <ion-content>         <div>         ONLINE: {{vm.isOnline}}        </div>   </ion-content> </ion-view> 

Result:

ONLINE: true

However, in another controller/template this does not work and I have been at this for hours and hours:

        (function() {           'use strict';            angular             .module('MyApp')             .controller('HomeController', HomeController);            HomeController.$inject = ['$scope','ConnectivityMonitor'];            function HomeController($scope, ConnectivityMonitor) {              var vm = this;              vm.isOnline = ConnectivityMonitor.isOnline();               activate();               ////////////////              function activate() {               }            }         })();         <ion-content class="background" ng-controller="HomeController as vm">        <p>ONLINE: {{vm.isOnline}}</p>      </ion-content> 

Result:

ONLINE: {{vm.isOnline}}

Here ^^^ it seems that angular is not performing the databinding. I have all of my relevant controllers in index.html, as well as angularjs references.

Here is my implementation of the "ConnectivityMonitor" service:

    (function() {         'use strict';          // http://www.joshmorony.com/monitoring-online-and-offline-states-in-an-ionic-application/         angular.module('MyApp').factory('ConnectivityMonitor', ['$rootScope', '$cordovaNetwork', connectivityMonitor]);          function connectivityMonitor($rootScope, $cordovaNetwork) {            return {             isOnline: function () {               if (ionic.Platform.isWebView()) {                 return $cordovaNetwork.isOnline();               } else {                 return navigator.onLine;               }             },              isOffline: function () {               if (ionic.Platform.isWebView()) {                 return !$cordovaNetwork.isOnline();               } else {                 return !navigator.onLine;               }             }           };          }        }     )(); 

Any idea why this would not be working? I'm new to AngularJS and Ionic so I'm thinking there is some nuance or convention that I'm overlooking. Thanks.

Related Articles

  • Ionic: trouble using ngCordova to check online/offline statusMarch 11

    I'm using ngCordova "Network Information" plugin to get the online/offline status of the host device. I have followed this tutorial (which excellent, as are his other posts): Josh Morony - Monitoring Online and Offline States in an Ionic Applica

  • Checking networking hardware status on LinuxFebruary 8

    Is there a Linux tool to check hardware boards status? In Windows you have the hardware dialog which shows you lines like "your hardware is working properly" (I don't have the English version so the string may actually be different, but you got

  • Can a (hw) loadbalancer check on HTTP status codes?August 28

    We're currently developing several websites using 2 web front-end servers (using apache and tomcat/jboss) with a loadbalancer in front of them. Since I'm a programmer, not a sysadmin, I can only guess what a decent hardware loadbalancer is capable of

  • Is there any tool present in Linux to check the delivery status of any mail sent using QmailDecember 9

    Is there any tool present in Linux to check the delivery status of any mail sent using Qmail or looking into the log file is the only option ? Warm Regards Supratik --------------Solutions------------- I can't see any other option for the same but yo

  • Determine Publishing Page check-in/publish status programmaticallyFebruary 2

    Is there a way to determine the check-in/publish status of a Publishing Page programmatically? For example to determine whether the page is checked out (and to whom), whether the page has a published version, etc. --------------Solutions-------------

  • Force Google Analytics to re-check tracking code status?June 3

    Is there a way to force Google Analytics to re-check tracking code status? I've just installed the tracking code, but I want Google Analytics to verify whether I installed the code correctly. Google Analitycs's last check was few hours ago, before I

  • Check processor status- check processor/cpu status and failed/off statusDecember 11

    I want to Check processor status- check processor/cpu status and failed/off status so for that I used command prtdiag and want to fetch the cpu status only from that. how can i do that? --------------Solutions------------- just use psrinfo. $ psrinfo

  • Check RAID rebuild status of R710?April 4

    How can I check the rebuild status of a RAID volume without booting into the PERC utility in CentOS via the command-line? --------------Solutions------------- I found I could check the status with MegaCli as ewwhite mentioned: MegaCli64 -PDRbld -Show

  • How to check the exit status of an application after using 'open' in shellSeptember 3

    I've looked all over for this and I'm not entirely sure how to do this. I want to use a bash script to open an application using 'open' and then check the exit status of the application after it has finished. As far as I am aware, open -W will exit w

  • How can I check the SMART status of a drive on Ubuntu 14.04 through 15.10?

    How can I check the SMART status of a drive on Ubuntu 14.04 through 15.10?September 24

    How can I check the SMART status of a drive under 14.04? I've seen Checking HD SMART status on a fresh install but it doesn't seem to apply under 14.04. --------------Solutions------------- For a commandline version, you need to install the smartmont

  • Tool for Checking App review StatusJuly 22

    Is there any app or tool for checking app review status of App Store. I develop iOS apps for different clients and different iTunes accounts, so every time I have to login every iTunes account for checking the app review status. It would be a great h

  • How to check the submission status of my Safari extension?January 15

    I submitted an extension for Safari a couple of days ago. How can I check for its status, and what is the usual process for an approval? I checked on developer.apple.com portal, but cant find it anywhere. Someone has asked same question on Quora arou

  • WORDPRESS How to show online offline status of a user in comment pageJanuary 17

    I am using wordpress for my website i want to show status of any user in comment page eg. Online or Offline. i serached web and found this topic How to display the status of users (online - offline) in archive.php into this they showed this code In t

  • How to check the restart status of a remote machine?January 22

    I have a server machine that I don't have physical access to at the moment. I needed to do a restart so I remote connected to the server and hit restart... it's been down a while. If I try and remote connect again I am not able to as it is currently

  • Check if offline map is availableJanuary 14

    I'm using MapControl in my WinPhone 8.1 Store App. I have a collection of points, which are inside one specific country (e.g. Germany). I want to display the map with those points and certain Zoom Level. However, it doesn't work when my device is off

  • designing an "online / offline " status indicator and examples of existing ones with good practice

    designing an "online / offline " status indicator and examples of existing ones with good practiceMarch 8

    Im trying to integrate an online / offline User Interface element in my application ( web app) I have some trouble getting it matches with the other user interface elements, and wonder what you guys here think of it - and in best practice could recom

  • How to check the physical status of an ethernet port in Linux?May 30

    I want to check if a specified ethX is physically up or down. How do I do that with the command line? --------------Solutions------------- ethtool ethX for example ethtool eth0 or ethtool eth1 provides Settings for eth0: Supported ports: [ TP ] Suppo

  • What process should nagios look for to check IIS7 running status?April 27

    We're finally rolling out Server 2008 systems and our old IIS6 check looked for IIS.exe, which doesn't appear to be used anymore. Is there a better process name to look for? We already have network availability checks in place, but having multiple fo

  • Show online/offline status of email address in Excel from MS CommunicatorMay 23

    I got a sheet of employees in Excel 2010 and would like to see who's online on Communicator jst by looking at the sheet and the row with employee's name. Each employee has the firm's email address in the sheet, of course. How can I access this inform

  • Trouble deciphering a deadlock in an innodb status logJune 6

    We are accessing MySQL from the Microsoft ADO.NET connector. Occasionally we are seeing the following deadlock in our innodb status and haven't been able to identify the cause of the problem. It looks like transaction (2) is waiting for and holding t

Copyright (C) 2018 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.611 s.