diff --git a/app/templates/client/app/main/main.controller.js b/app/templates/client/app/main/main.controller.js index db9bbd5c3..f69ad1e8b 100644 --- a/app/templates/client/app/main/main.controller.js +++ b/app/templates/client/app/main/main.controller.js @@ -2,30 +2,32 @@ (function() { -function MainController($scope, $http<% if (filters.socketio) { %>, socket<% } %>) { - var self = this; - this.awesomeThings = []; - - $http.get('/api/things').then(function(response) { - self.awesomeThings = response.data;<% if (filters.socketio) { %> - socket.syncUpdates('thing', self.awesomeThings);<% } %> - });<% if (filters.models) { %> - - this.addThing = function() { - if (self.newThing === '') { - return; +class MainController { + + constructor($http<% if (filters.socketio) { %>, $scope, socket<% } %>) { + this.$http = $http; + this.awesomeThings = []; + + $http.get('/api/things').then(response => { + this.awesomeThings = response.data;<% if (filters.socketio) { %> + socket.syncUpdates('thing', this.awesomeThings);<% } %> + });<% if (filters.socketio) { %> + + $scope.$on('$destroy', function() { + socket.unsyncUpdates('thing'); + });<% } %> + }<% if (filters.models) { %> + + addThing() { + if (this.newThing) { + this.$http.post('/api/things', { name: this.newThing }); + this.newThing = ''; } - $http.post('/api/things', { name: self.newThing }); - self.newThing = ''; - }; + } - this.deleteThing = function(thing) { - $http.delete('/api/things/' + thing._id); - };<% } if (filters.socketio) { %> - - $scope.$on('$destroy', function() { - socket.unsyncUpdates('thing'); - });<% } %> + deleteThing(thing) { + this.$http.delete('/api/things/' + thing._id); + }<% } %> } angular.module('<%= scriptAppName %>')