Is it the responsibility of the controller or service to check if the device is connected to the network


I am confused.

As of now, I am creating a HTML5's sessionStorage variable in block and once set I am using a service to set the sessionStorage variable to keep the value true or false depending on the network connection. All of the above happens in the .run block

When I need the value of the sessionStorage's variable i my view / controller I just resolve it in the .config block and pass the key to the controller.

Is this the correct way of doing things? Am I breaking any fundamental OOP practices?


That is similar to what I am doing. However, I use ngCordova’s $cordovaNetwork service before I do any action that needs to check for a connection. I inject the $cordovaNetwork service into my controller and call $cordovaNetwork.isOnline(). I don’t quite get how you are using the .config block. I may not have the full picture, but that seems unnecessary to me.

If you need a code example, just holler.

.state('name', {
        url: "/name",
        templateUrl: "templates/name.html",
        controller: "NameController",
        resolve: {
            connectionStatus : function(ConnectionService){
                return ConnectionService.getConnectionStatus();

Something like this in .config and I just inject connectionStatus to the controller that needs it.
And now I noticed that injecting connectionStatus to controller is completely unnecessary. Dont know why I did that.