Stricker2014-02-10 18:55:31
Stricker, 2014-02-10 18:55:31

AngularJS and server connection dependency

Greetings, the problem is this, there is a service for working with WebSocket and almost the entire application is tied to it. How to make the application work only when the connection is made? Those. When you start the application, wait for the connection, only then interact with the application?
Just simply this service - https://github.com/ZloyDyadka/websocket-angular/bl...
And when, for example, I call in the controller -

app.controller('headerCtrl', ['$scope', 'ws', '$q', function($scope, ws, $q) {
        "method"    : "getCountMsg",
        "params"    : ""
            $scope.countMsg = d;

The connection is not established instantly, but the request to the server is sent immediately - to which it receives an error that there is no connection.
Those. I need to somehow make the controllers work depending on whether there is a connection

Answer the question

In order to leave comments, you need to log in

1 answer(s)
maxaon, 2014-02-10

Bad library, look for something better.
The method callshould always return a promise, not just when the connection happened ( ready===true).
In addition, this code clutters up the global scope of the variable ready. It also uses console instead of the $log service.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question