Skip to content

Instantly share code, notes, and snippets.

View MartinHerren's full-sized avatar

Martin Herren MartinHerren

View GitHub Profile
@ae6rt
ae6rt / AngularJS-apply.scope
Last active August 30, 2018 22:37
An AngularJS websocket service that updates a controller scope variable
var app = angular.module('app', []);
app.controller('controller', function ($scope, websocketService) {
$scope.msg = "...";
websocketService.start("ws://localhost:8080/events", function (evt) {
var obj = JSON.parse(evt.data);
$scope.$apply(function () {
$scope.msg = obj.message
});