-
-
Save arvindr21/8c874bb844778f5a5d91 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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