/app/templates/client/app/main/main.controller(js).js
JavaScript | 27 lines | 23 code | 4 blank | 0 comment | 5 complexity | 6b1657462fdbde6a096ed731ae0e88b1 MD5 | raw file
- 'use strict';
- angular.module('<%= scriptAppName %>')
- .controller('MainCtrl', function ($scope, $http<% if(filters.socketio) { %>, socket<% } %>) {
- $scope.awesomeThings = [];
- $http.get('/api/things').success(function(awesomeThings) {
- $scope.awesomeThings = awesomeThings;<% if(filters.socketio) { %>
- socket.syncUpdates('thing', $scope.awesomeThings);<% } %>
- });
- <% if(filters.mongoose) { %>
- $scope.addThing = function() {
- if($scope.newThing === '') {
- return;
- }
- $http.post('/api/things', { name: $scope.newThing });
- $scope.newThing = '';
- };
- $scope.deleteThing = function(thing) {
- $http.delete('/api/things/' + thing._id);
- };<% } %><% if(filters.socketio) { %>
- $scope.$on('$destroy', function () {
- socket.unsyncUpdates('thing');
- });<% } %>
- });