如果我把從doStuff
connect
,我得到「套接字連接」,但callback
不叫消息。我在這裏錯過了什麼?無極回調不叫角JS
$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);
});
}
我在使用socket.io時出現了同樣的問題@ markrajcok – srinivas 2016-09-07 15:45:16