angular-websocket
angular-websocket copied to clipboard
Inside onClose callback scope changes never are applied
This code doesn't work:
ws.onClose(function (e) {
$scope.anyVariable = anyValue;
}
I mean, scope variables are changed but not binding to the view. Binding is off
I fixed it using $scope.$digest(), but why not update?
Same here, didn't thought of it first and wasted nearly an hour. Surrounding all on...()
callbacks with $apply would be a good idea!
Same here, I $broadcast
an event to let the controller know, and the angular-websocket callbacks to onClose
/onError
are not made within an $apply block, so need to be wrapped:
ws.onError(function(event) {
$rootScope.$apply(function() {
$rootScope.$broadcast("wschange", 0);
});
});
ws.onClose(function(event) {
$rootScope.$apply(function() {
$rootScope.$broadcast("wschange", 0);
});
});
Same here, I think this should be documented or changed. Having onMessage
update scope vars but not onClose
was confusing until I found this issue.