title: AngularJS echo very fast changes
body: <p>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 : </p>
  
  <pre><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()
              }
          };
      })
  </code></pre>
  
  <p>The Controller : </p>
  
  <pre><code>.controller('SocketController', function ($scope, MyData) {
  
          $scope.MyData  = MyData
          $scope.MyData.open()
  
      })
  </code></pre>
  
  <p>The view : </p>
  
  <pre><code>{{ connection_status }}
  &lt;div ng-switch="connection_status"&gt;
  
      &lt;a ng-switch-when="offline" ng-click="MyData.open()"&gt;Connect&lt;/a&gt;
      &lt;a ng-switch-when="online" ng-click="MyData.close()"&gt;Disconnect&lt;/a&gt;
      &lt;a ng-switch-when="connecting" ng-click="MyData.close()"&gt;cancel&lt;/a&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>In this code {{ connection_status }} dont works correctly that means , we have two possible cases</p>
  
  <ol>
  <li>{{ connection_status }} is online (correct) and $rootScope.connection_status is online</li>
  <li>{{ connection_status }} is connecting (incorrect) but $rootScope.connection_status is online why?</li>
  </ol>