Answer the question
In order to leave comments, you need to log in
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) {
ws.call({
"method" : "getCountMsg",
"params" : ""
}).then(function(d){
$scope.countMsg = d;
})
}]);
Answer the question
In order to leave comments, you need to log in
Bad library, look for something better.
The method call
should 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 questionAsk a Question
731 491 924 answers to any question