PageRenderTime 40ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/app/templates/client/app/main/main.controller(js).js

https://gitlab.com/javajamesb08/generator-angular-fullstack
JavaScript | 27 lines | 23 code | 4 blank | 0 comment | 5 complexity | 6b1657462fdbde6a096ed731ae0e88b1 MD5 | raw file
  1. 'use strict';
  2. angular.module('<%= scriptAppName %>')
  3. .controller('MainCtrl', function ($scope, $http<% if(filters.socketio) { %>, socket<% } %>) {
  4. $scope.awesomeThings = [];
  5. $http.get('/api/things').success(function(awesomeThings) {
  6. $scope.awesomeThings = awesomeThings;<% if(filters.socketio) { %>
  7. socket.syncUpdates('thing', $scope.awesomeThings);<% } %>
  8. });
  9. <% if(filters.mongoose) { %>
  10. $scope.addThing = function() {
  11. if($scope.newThing === '') {
  12. return;
  13. }
  14. $http.post('/api/things', { name: $scope.newThing });
  15. $scope.newThing = '';
  16. };
  17. $scope.deleteThing = function(thing) {
  18. $http.delete('/api/things/' + thing._id);
  19. };<% } %><% if(filters.socketio) { %>
  20. $scope.$on('$destroy', function () {
  21. socket.unsyncUpdates('thing');
  22. });<% } %>
  23. });