(function () {
  'use strict';

  angular
    .module('scholorships')
    .controller('ApplicationsListController', ApplicationsListController);

  ApplicationsListController.$inject = ['ApplicationsService', 'SemesterService', '$scope', '$http'];

  function ApplicationsListController(ApplicationsService, SemesterService, $scope, $http) {
    var vm = this;

    vm.semesters = SemesterService.getLastFourSemesters({});
    $scope.applications = ApplicationsService.query(function (data){
      $scope.applications = data;
    });

    $scope.propertyName = 'age';
    $scope.reverse = true;
    $scope.sortBy = function(propertyName) {
      $scope.reverse = (propertyName !== null && $scope.propertyName === propertyName) ? !$scope.reverse : false;
      $scope.propertyName = propertyName;
      //$scope.applications = orderBy(friends, $scope.propertyName, $scope.reverse);
    };

    $scope.checkName = function(data, id) {
      if (id === 2 && data !== 'awesome') {
        return 'Username 2 should be `awesome`';
      }
    };

    $scope.saveApplication = function(data, id) {
      angular.extend(data, { id: id });
      return $http.post('/saveUser', data);
    };

    // remove user
    $scope.removeApplication = function(index) {
      //$scope.applications.splice(index, 1);
    };
  }


})();

@@ -890,24 +890,58 @@
     
-$scope.checkName
+// Remove Application%0A    $scope.removeApplication
  = f
@@ -944,32 +944,29 @@
  = function(
-data, id
+index
 ) %7B%0A      if
@@ -969,42 +969,67 @@
   if
- (id === 2 && data !== 'awesome') 
+(confirm('%C3%84r du s%C3%A4ker p%C3%A5 att du vill radera ans%C3%B6kningen?'))
 %7B%0A  
@@ -1038,283 +1038,205 @@
     
-return 'Username 2 should be %60awesome%60';%0A      %7D%0A    %7D;%0A%0A    $scope.saveApplication = function(data, id) %7B%0A      angular.extend(data, %7B id: id %7D);%0A      return $http.post('/saveUser', data);%0A    %7D;%0A%0A
+// Send delete request to server.%0A        ApplicationsService.delete(%7B applicationId: $scope.applications%5Bindex%5D._id %7D, function(err)%7B%0A      
     // 
-r
+R
 emove 
-user%0A    $scope.removeApplication = function(index) %7B
+deleted application from $scope
 %0A      
-//
+    
 $sco
@@ -1269,16 +1269,36 @@
 ex, 1);%0A
+        %7D);%0A      %7D%0A
     %7D;%0A 

add remove application feature