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