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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -