Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem when websocket was disconnect #96

Open
mj-mehdizadeh opened this issue Aug 4, 2016 · 0 comments
Open

problem when websocket was disconnect #96

mj-mehdizadeh opened this issue Aug 4, 2016 · 0 comments

Comments

@mj-mehdizadeh
Copy link

Hi i am using angular websocke
when i switch on websocket and open the connection or close a connection the $rootScope model was not change.
Service code :

.factory("MyData", function($websocket, $rootScope) {
        return {
            open: function () {
                $rootScope.connection_status = 'connecting';
                window.dataStream =  $websocket(Config.socketUrl);

                dataStream.onError(function () {
                      console.log('error')
                })
                dataStream.onOpen(function () {
                    $rootScope.connection_status = 'online';
                    console.log('now online',$rootScope.connection_status)
                })

                dataStream.onClose(function () {
                    $rootScope.connection_status = 'offline';
                    console.log('now offline',$rootScope.connection_status)
                })
            },
            close: function () {
                dataStream.close()
            }
        };
    })

The Controller :

.controller('SocketController', function ($scope, MyData) {

        $scope.MyData  = MyData
        $scope.MyData.open()

    })

The view :

{{ connection_status }}
<div ng-switch="connection_status">

    <a ng-switch-when="offline" ng-click="MyData.open()">Connect</a>
    <a ng-switch-when="online" ng-click="MyData.close()">Disconnect</a>
    <a ng-switch-when="connecting" ng-click="MyData.close()">cancel</a>
</div>

In this code {{ connection_status }} dont works correctly that means , we have two possible cases

  1. {{ connection_status }} is online (correct) and $rootScope.connection_status is online
  2. {{ connection_status }} is connecting (incorrect) but $rootScope.connection_status is online why?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant