When I try to post data from angular to my nodejs backend it doesn't work.
[Backend] This is the function that catches the posted data. I tested it with postman and it worked. The console.log is just for testing. I have also a bodyParser running.
register : function (req, res) {
console.log(req.body);
res.json(req.body);
}
[Frontend] This is the function that I call to send the data. I tested it with breakpoints and a console.log and the function is called. I think I tested all the possible ways to format the header.
import { Injectable } from '@angular/core';
import { Http, Response, Headers, RequestOptions } from '@angular/http';
@Injectable()
export class DataService {
constructor (private http: Http) {}
register(user:string): void{
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
this.http.post('http://127.0.0.1:5000/register', { user }, options);
}
}
When I put a breakpoint on the this.http.post(...); I get this: link to image