Skip to content

Instantly share code, notes, and snippets.

@arvindr21
Forked from balthazar/home.controller.js
Last active August 29, 2015 14:22
Show Gist options
  • Save arvindr21/8c874bb844778f5a5d91 to your computer and use it in GitHub Desktop.
Save arvindr21/8c874bb844778f5a5d91 to your computer and use it in GitHub Desktop.
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();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment