You do not send data to the node / express API from Angular

0

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'}

    
asked by Charl Barrera 26.09.2018 в 02:05
source

0 answers