2

I am making a simple ToDoApp with MEAN (Angular 2) stack but I have a problem with the http.post request. Always when I am running the post method, the current JSON object gets inserted into the database. But right after I get an error message and also my current server connection breaks down.

Insert method:

post method

The error in the console:

Console error

CORS is allowed on the backend side and I don't know what else to try.

Any suggestions?

Mika Sundland
  • 18,120
  • 16
  • 38
  • 50
Mensa10
  • 103
  • 1
  • 1
  • 6
  • There are few mistakes in your question.. use the right one –  May 26 '17 at 18:04
  • You may not stringify your body (task object). I would try to remove RequestOptions instance and set the post method like this: this.http.post('api/task', task, {headers})... Hope help you! – mryuso92 Apr 29 '20 at 05:43

1 Answers1

0

Maybe because http.post returns a promise, not an array as you assume by calling .map on the result.

See https://docs.angularjs.org/api/ng/service/$http#post.

A valid example would be:

$http
.post('/someUrl', data, config)
.then(successCallback, errorCallback);
Ioan
  • 5,152
  • 3
  • 31
  • 50
  • 1
    That's maybe a solution for AngularJS but i am using Angular2 and i think i can't use your answer! – Mensa10 May 26 '17 at 20:51