title: Angularjs calling java functions
body: <p>I have one simple web application in JAVA and angularjs. Where users can add persons to app and remove them from mongo database. </p>
  
  <p>My problem is, I don't know exactly how angular communicates with java and calls Java functions. For example if i want to delete a person from my database after a button click. </p>
  
  <p>here's some code</p>
  
  <p><strong>persons.html</strong></p>
  
  <pre><code>&lt;a for-authenticated ng-click="remove(s.id)" href=""&gt; &lt;i
       class="pull-right glyphicon glyphicon-remove"&gt;&lt;/i&gt;
  &lt;/a&gt;
  </code></pre>
  
  <p><strong>app.js</strong></p>
  
  <pre><code>var app = angular.module('conferenceApplication', [
  'ngCookies',
  'ngResource',
  'ngSanitize',
  'ngRoute',
  'ui.bootstrap',
  'angularFileUpload',
  'ngQuickDate']);
  
  
   app.config(function ($routeProvider) {
      $routeProvider
        .when('/home', {
             templateUrl: '/partials/home.html',
             controller: 'HomeCtrl'
        })
        .when('/speakers', {
            templateUrl: '/partials/person-list.html',
            controller: 'PersonListCtrl'
        })
  });
  app.controller('PersonListCtrl', function ($scope,$http, $modal, $log, $route, PersonService) {
  $scope.remove = function(id) {
      var deletedPerson = id ? PersonService.remove(id, function(resp){
          deletedPerson = resp;
      }) : {};
  };
  }
  </code></pre>
  
  <p><strong>PersonService.js</strong></p>
  
  <pre><code>app.service('PersonService', function ($log, $upload, PersonResource) {
  this.getById = function (id, callback) {
      return PersonResource.get({personId: id}, callback);
  };
  this.remove = function(id, callback) {
      return PersonResource.deleteObject({PersonId: id}, callback);
  }
  }
  </code></pre>
  
  <p><strong>PersonResource.js</strong></p>
  
  <pre><code>app.factory('PersonResource', function ($resource) {
  return $resource('rest/person/:personId',
      {
          personId: '@personId'
      },
      {
          'update': { method: 'PUT' }
      })
  </code></pre>
  
  <p>});</p>
  
  <p>also i have a java class where i want to delete this person from database</p>
  
  <p><strong>PersonResource.java</strong></p>
  
  <pre><code>@Controller
   @RequestMapping("/person")
     public class PersonResource {
  
       @Autowired
       private PersonService personService;
  
       @RequestMapping(method = RequestMethod.GET, value = "/{id}")
       public ResponseEntity&lt;Person&gt; deleteObject(@RequestBody Person id) {
          Person person = personService.findById(id);
          personService.deleteObject(id);
          return new ResponseEntity&lt;Person&gt;(person, HttpStatus.ACCEPTED);
       }
     }
  </code></pre>
  
  <p><strong>PersonRepository</strong></p>
  
  <pre><code>  @Override
    public void deleteObject(String id) {
        getTemplate().remove(new Query(Criteria.where("id").is(id)), Person.class);
    }
  </code></pre>
  
  <p>the getTemplate() returns MongoTemplate.</p>
  
  <p>Can anyone tell me what i am doing wrong to get my entry deleted from database ?</p>