Skip to content Skip to sidebar Skip to footer

Mean Stack: Post Method Is Not Reflecting In Database

I'm trying to pass some data through HTTP post method but it is not reflecting in the database. This is code. addJobList(jobitem) { let headers = new Headers(); headers.app

Solution 1:

You don't need to encode your data like in this example and you must return your this.http.post.

addJobList(jobitem) {
    let headers = newHeaders();
    headers.append('Content-Type','application/json');
    const selected = {
      companyTitle : jobitem.company,
      jobTitle : jobitem.jobtitle,
      location : jobitem.location
    }
    returnthis.http.post('http://localhost:3000/api/appliedjobs', selected, { headers: headers })
    .map(res => res.json());
  }

To use it you need to subscribe to your addJobList method, http.post is an observable and needs to be subscribed to make the http call :

addJobList(theJobItem).subscribe(data => console.log(data));

Post a Comment for "Mean Stack: Post Method Is Not Reflecting In Database"