POST in MEAN app send null

I am writing a CRUD app using MEAN stack and when I try to POST an object to add it to a collection in the mongo database it adds objects that have only "id", "update_date" and "_v".

It works fine and adds proper objects when I just open a simple HTML file with a form of method="post", but when I try to use this inside the angular app it just sends the objects without the make, year and model properties.

This is my add-car.component.html:

  <h1>Add car</h1>

  <form (ngSubmit)="addCar()">
    <div class="form-group">
      <label for="make">Make</label>
      <input type="text" name="make" class="form-control" [(ngModel)]="car.make">

    <div class="form-group">
      <label for="model">Model</label>
      <input type="text" name="model" class="form-control" [(ngModel)]="car.model">

    <div class="form-group">
      <label for="year">Year</label>
      <input type="text" name="year" class="form-control" [(ngModel)]="car.year">

    <button type="submit" class="btn btn-default">Add</button>


This is the add-car.component.ts :

import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Router } from '@angular/router';

  selector: 'app-add-car',
  templateUrl: './add-car.component.html',
  styleUrls: ['./add-car.component.css'],
  encapsulation: ViewEncapsulation.None
export class AddCarComponent implements OnInit {

  car = {};

  constructor(private http: HttpClient,  private router: Router) { }

  ngOnInit() {

  addCar() {'http://localhost:3001/cars',
      res => {
      }, (err) => {


Here's the part of code defining the mongoose model:

var mongoose = require('mongoose');

var CarSchema = new mongoose.Schema({
    make: String,
    model: String,
    year: String,
    updated_date: { type: Date, default: },

module.exports = mongoose.model('Car', CarSchema, 'cars');

I have no idea why this isn't working, it's probably something stupid I'm not seeing.

1 answer

  • answered 2018-03-13 22:50 Matt

    The problem was with the backend server which didn't have this:


    So it couldn't parse the object that was sent as a json file.