Comments (2)
ng-websockets events doesn't trigger a angular $digest. (Which I really think it should, btw.). Anyway, all you have to do is trigger it yourself.
$scope.message = message;
$scope.apply();
This can potentially trigger an error if angular is already in a digesting state. One easy way to waif for the previous digest to complete is to use $timeout. (You have to inject it):
angular.module('bedappApp').controller('MainCtrl', function ($scope, $timeout, $websocket) {
...
ws.$on('event', function (message) {
$timeout(function(){
$scope.message = message;
});
});
(Using $timeout without a delay-value will run a function immediately or as soon as the current digest finishes).
from ng-websocket.
I am new to AngularJS and this one was driving me nuts, I even looked everything there is to know about scopes and inheritance.
The solution of @kumorig works, but is missing the '$':
$scope.message = message;
$scope.$apply();
It really is a valid workaround, but it kind of "de-angularizes" the main purpose of websockets:
$apply() is used to execute an expression in angular from outside of the angular framework.
Is there another way of achieving this with ng-websocket or something that we are missing?
from ng-websocket.
Related Issues (20)
- Browser support & fallback? HOT 1
- Protocol Chrome error HOT 9
- how should i construct a socket to ws://localhost:12345/abc/ac ? HOT 1
- Exponential number of reconnects HOT 4
- ERR_CONNECTION_REFUSED HOT 4
- Updating the angular version? HOT 3
- update url in reconnect HOT 3
- ws socket instance HOT 2
- server reject vs. losing connection HOT 2
- Is it possible to send credentials when connecting to the web-socket?
- $on custom events not working properly HOT 1
- onclose does not pass event HOT 1
- $get return undefined
- Project maintained ? HOT 1
- Socket $destroy HOT 1
- How does this project compare to https://github.com/AngularClass/angular-websocket
- 60 seconds of Timeout period, How to decrease it?
- Connect with headers
- Cannot reopen websocket after calling $close() HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ng-websocket.