如果我connect
从调用doStuff
,我会收到“套接字已连接”的消息,但callback
不会调用。我在这里想念什么?
$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);
});
}