I'd like to use socketstream's RPC over websockets abstraction while using Angular for MVC. Can anyone (probably in the Angular community) point me in the right direction to learn how to use a custom RPC-type data source to update Angular's models in the most idiomatic way?
1 Answer
If you want to simply sync a model with the server, here's a good example to start with that Misko Hevery made for socket.io: https://github.com/mhevery/angular-node-socketio
5 Comments
BHP
OK, so basically I have to define a service that listens for updates from both the GUI and the server and syncs them. One Q-- he uses $updateView, but that seems to be deprecated. Basically what I'm looking for is how to idiomatically tell Angular that the model has changed so that it can update any data bound elements.
Andrew Joslin
Use scope.$apply for that now docs.angularjs.org/api/ng.$rootScope.Scope#$apply. Example: scope.$apply(function() { scope.myValue = 6; });
BHP
Hope this isn't a dumb question, but when I define my service, do I pass in $apply?
BHP
i mean in this part of the example: angular.service('sharedModel', function($updateView). just trying to understand the context that the service will be called when I make it a dependency of one of my controllers.
Andrew Joslin
There's no such thing as a dumb question. :) and you can inject $rootScope into your service and do $rootScope.$apply();