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