If I call connect
from doStuff
, I get the message that "the socket is connected", but the callback
is not called. What am I missing here?
$scope.connect = function() {
var defer = $q.defer();
ws = new WebSocket("ws://server.com:port");
ws.onopen = function(){
console.log("Socket connected");
defer.resolve("socket connected");
};
return defer.promise;
}
$scope.doStuff = function() {
$scope.connect().then(function(data) {
console.log("And we're off!", data);
});
}