janpantel / angular-sails

An angular module for using the sails socket.io api
MIT License
307 stars 56 forks source link

Update documentation for $sails.on #68

Closed giannoug closed 9 years ago

giannoug commented 9 years ago

According to the documentation,

$sails.on("bars", function (message) {
  if (message.verb === "created") {
    $scope.bars.push(message.data);
  }
});

For my implementation (based on a vanilla Sails 0.11.0 version using angular-sails 1.1.3), the callback is never executed. I'm able to POST and GET using the $sails service, using websockets. For some reason $sails.on doesn't work. I have also tried using promised without success.

TheSharpieOne commented 9 years ago

$sails.on('<eventName/collectionName>', <function callback(){...}>) is the right syntax. It has callback vs promise as the callback can happen many time but a promise can only be resolved once. The documentation is correct. on() is different from the others as it only calls the callback when the server sends an event with the event/collection name you subscribe to. Simply subscribing to the event/collection will not trigger the callback to be fired. One way to make sure the server (SailsJs) is sending something that would trigger the event is to view the socket data being sent back and fourth using Google Chrome's DevTools. If you see the event you are subscribing to being sent and the callback still not being fired, take a screenshot of the DevTools screen showing the event and put it in this ticket along with the actual $sails.on(...) code you are using to subscribe to the event.

Also, you may want to ensure the $sails.on(...) call is being fired. The easiest way is to put console.log('About to call $sails.on()'); and console.log('Finished calling $sails.on()'); before and after the $sails.on(...) call respectfully.

TheSharpieOne commented 9 years ago

Merged in #80 (c309c32a36)