|
2 | 2 |
|
3 | 3 | (function() { |
4 | 4 |
|
5 | | -function MainController($scope, $http<% if (filters.socketio) { %>, socket<% } %>) { |
6 | | - var self = this; |
7 | | - this.awesomeThings = []; |
8 | | - |
9 | | - $http.get('/api/things').then(function(response) { |
10 | | - self.awesomeThings = response.data;<% if (filters.socketio) { %> |
11 | | - socket.syncUpdates('thing', self.awesomeThings);<% } %> |
12 | | - });<% if (filters.models) { %> |
13 | | - |
14 | | - this.addThing = function() { |
15 | | - if (self.newThing === '') { |
16 | | - return; |
| 5 | +class MainController { |
| 6 | + |
| 7 | + constructor($http<% if (filters.socketio) { %>, $scope, socket<% } %>) { |
| 8 | + this.$http = $http; |
| 9 | + this.awesomeThings = []; |
| 10 | + |
| 11 | + $http.get('/api/things').then(response => { |
| 12 | + this.awesomeThings = response.data;<% if (filters.socketio) { %> |
| 13 | + socket.syncUpdates('thing', this.awesomeThings);<% } %> |
| 14 | + });<% if (filters.socketio) { %> |
| 15 | + |
| 16 | + $scope.$on('$destroy', function() { |
| 17 | + socket.unsyncUpdates('thing'); |
| 18 | + });<% } %> |
| 19 | + }<% if (filters.models) { %> |
| 20 | + |
| 21 | + addThing() { |
| 22 | + if (this.newThing) { |
| 23 | + this.$http.post('/api/things', { name: this.newThing }); |
| 24 | + this.newThing = ''; |
17 | 25 | } |
18 | | - $http.post('/api/things', { name: self.newThing }); |
19 | | - self.newThing = ''; |
20 | | - }; |
| 26 | + } |
21 | 27 |
|
22 | | - this.deleteThing = function(thing) { |
23 | | - $http.delete('/api/things/' + thing._id); |
24 | | - };<% } if (filters.socketio) { %> |
25 | | - |
26 | | - $scope.$on('$destroy', function() { |
27 | | - socket.unsyncUpdates('thing'); |
28 | | - });<% } %> |
| 28 | + deleteThing(thing) { |
| 29 | + this.$http.delete('/api/things/' + thing._id); |
| 30 | + }<% } %> |
29 | 31 | } |
30 | 32 |
|
31 | 33 | angular.module('<%= scriptAppName %>') |
|
0 commit comments