Most non-angular callbacks happen outside of the angular digest cycle. What
happens if you call $scope.$apply(function() {$scope.message =
message.data}) instead?e On Wed, Sep 10, 2014 at 10:13 AM, marcos rebelo <[email protected]> wrote: > > I'm +- new in Frontend work and I'm willing to learn. > > I'm trying to use WebSockects to change my page and getting crazy on the > process. Consider the class MyWS a working WS. > > > <html ng-app="todoApp"> > <head> > <script src="/assets/js/angular.min.js"></script> > <script src="/assets/js/underscore.js"></script> > <script src="/assets/js/MyWS.js"></script> > <script> > angular.module('todoApp', []) > .controller('WebsocketController', ['$scope', function( > $scope) { > $scope.users = [{"firstName" : "firstName", "lastName" > : "lastName"}]; > $scope.message = "crazy"; > var counter = 0; > var ws = MyWS("ws://localhost:9000/websocket", > function(ws) { > $scope.message = "Socket has been opened!"; > ws.send("RelevantUsers", {"userId":"Hello World"}, > function(message) { > $scope.message = message.data; > var userIds = _.map(message.data.results, > function(elem) { return elem.userId }); > > ws.send("LoadUsers", {"userIds": userIds}, > function(message) { > _.each(message.data.users, function(elem) > { > $scope.users.push(elem); > }); > console.log($scope.users); > }); > }); > }); > }]); > </script> > </head> > <body> > Hello World > <p></p> > <div ng-controller="WebsocketController"> > <div>{{ message }}</div> > <div ng-repeat="user in users" style="width:500px; float:left; > border:solid 2px #aaa; padding: 5px; margin: 5px"> > <div>{{user.firstName}} {{user.lastName}}</div> > </div> > </div> > </body> > </html> > > I get the {{ message }} set to "crazy" at the beggining and never changed, > actually the console.log($scope.users) works and I have 10 elements on the > array visible on the console after all this messages changed with the > server. > > My question is. Since all the steps seem to pass, why dont I have an > updated page at the end? > > Thanks for any help > > Best > MArcos > > -- > You received this message because you are subscribed to the Google Groups > "AngularJS" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/angular. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
