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

/client/app/main/main.controller.js

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