Angular JS - $ http.delete "Syntax error on token '.' comma expected on Eclipse

0

Eclipse keeps telling the error on $ http.delete, when other methods (like $ http.put, $ http.post) are not. What could it be? For example, $ http.put:

updateUser: function(user, id){
                return $http.put('http://localhost:8090/Spring4MVCAngularJSExample/user/'+id, user)
                        .then(
                                function(response){
                                    return response.data;
                                }, 
                                function(errResponse){
                                    console.error('Error while updating user');
                                    return $q.reject(errResponse);
                                }
                        );
        }

And now, $ http.delete

deleteUser: function(id){
                return $http.delete('http://localhost:8090/Spring4MVCAngularJSExample/user/'+id)
                        .then(
                                function(response){
                                    return response.data;
                                }, 
                                function(errResponse){
                                    console.error('Error while deleting user');
                                    return $q.reject(errResponse);
                                }
                        );
        }

Thanks for the help!

    
asked by anonymous 15.06.2016 / 20:20

1 answer

1

delete is a reserved word in JavaScript, and some interpreters have problems reading it in the middle of expressions (like the old Internet Explorer and probably the Eclipse interpreter).

What you can do to stop receiving this error is to invoke the method in another way:

$http({
  method: 'DELETE',
  url: 'http://exemplo.com'
})
.then(...);
  

$ http.delete is a shortcut to the above code.

or

$http['delete']('http://exemplo.com')
  .then(...);

But this error is only from IDE, the browser will interpret without problems, either with the code above or the way it is now.

    
15.06.2016 / 20:45