Skip to content

Instantly share code, notes, and snippets.

@balthazar
Last active August 29, 2015 14:14
Show Gist options
  • Save balthazar/9cd8b4b332948dc833f0 to your computer and use it in GitHub Desktop.
Save balthazar/9cd8b4b332948dc833f0 to your computer and use it in GitHub Desktop.
Bangular socket usage example
angular.module('test')
.controller('HomeCtrl', function ($scope, $http, Socket) {
var vm = this;
vm.items = [];
vm.lastMsg = '';
$http.get('/api/items').success(function (res) {
vm.items = res;
Socket.syncModel('Item', vm.items);
});
vm.add = function () {
$http.post('/api/items', { name: 'Some random name' });
};
vm.delete = function (id) {
$http.delete('/api/items/' + id);
};
Socket.on('msg', function (msg) {
vm.lastMsg = msg;
});
$scope.$on('$destroy', function () {
Socket.unsyncModel('Item');
Socket.clean();
});
});
@ripper2hl
Copy link

Line 22 ?
Socket.unsyncModel('Item');

@balthazar
Copy link
Author

Thank you 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment