socket.io - angularjs not executing deferred promise using angular-socket-io -
after solving this issue have new issue angular halting inside function that's waiting on socket connection.
controller:
.controller('myctrl',function($scope, socket) { var sendmsg = function(msg) { socket.then(function(msg) { socket.emit('newmsg', msg); }); } //simplified example var msg = 'hi mom!'; sendmsg(msg); });
the problem socket.emit()
never gets fired. if remove socket.then()
error socket.emit not function
. have wait socket initialized (which based on successful login in controller , broadcast through socket
factory). chicken-egg paradox? how can fire socket.emit in function? other similar functions work, such as:
socket.then(function(socket) { socket.on('connect',function() { //do something. works. }); });
the problem seems having 2 msg
parameters. however, second 1 socket:
var sendmsg = function(msg) { socket.then(function(socket) { // <-- socket.emit('newmsg', msg); }); }
Comments
Post a Comment