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

Asked

Viewed 315 times

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!

  • How about asking the question in Portuguese?

1 answer

1

delete is a reserved word in Javascript, and some interpreters have trouble reading it between expressions (such as 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 code above.

or

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.