Hi, I want to send an object to the database from an Angular 6 service. but my code sends me an empty object to the database, HELP:
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Data } from '../components/reservation/reservation.component';
@Injectable({
providedIn: 'root'
})
export class ReservationService {
baseUrl = 'http://localhost:3000';
basePost = 'http://localhost:3000/create';
private headers = new HttpHeaders().set('content-type', 'x-www-form-urlencoded');
constructor(private http: HttpClient) { }
getReservation() {
return this.http.get(this.baseUrl + '/list', {headers: this.headers});
}
**createReservation(data: Data) {
return this.http.post(this.basePost, data , {headers: this.headers})
.subscribe(dataS => console.log(dataS));
}**
}
// data has the value of {name: 'myname'}