since095 since095 - 1 month ago 11
Node.js Question

Post request restarts server without sending data (Angular2 / Node.js)

Here is my code;


import { Injectable } from "@angular/core";
import { Http, Headers, RequestOptions } from "@angular/http";
import { Observable } from "rxjs/Observable";
import 'rxjs/Rx';

import {Heatmap} from "./heatmap"

export class HeatmapService {
constructor (private _http: Http) {}

signup(heatmap: Heatmap) {
const body = JSON.stringify(heatmap);
const headers = new Headers({'Content-Type': 'application/json'});
const options = new RequestOptions({ headers: headers });

return'http://localhost:8080/create', body, options)
.map(response => response.json())
.catch(error => Observable.throw(error.json()));


import { Component, OnInit } from "@angular/core";
import { FormBuilder, FormGroup, FormControl, Validators } from "@angular/forms";

import { Heatmap } from "./heatmap";
import { HeatmapService } from "./heatmap.service";

templateUrl: 'js/app/heatmap/heatmap.component.html'

export class heatmapComponent implements OnInit {

myForm: FormGroup;

constructor(private formBuilder: FormBuilder, public heatService: HeatmapService) {}

onSubmit() {
const heatmap = new Heatmap(,,;

data => console.log(data),
error => console.error(error)

ngOnInit() {
this.myForm ={
name: ['', Validators.required],
data: ['', Validators.required],
country: ['', Validators.required]


<form [formGroup]="myForm" (ngSubmit)="onSubmit()">
<div class="form-group">
<label for="name">name</label>
<input type="text" id="name" class="form-control" formControlName="name">
<div class="form-group">
<label for="data">data</label>
<input type="text" id="data" class="form-control" formControlName="data">
<div class="form-group">
<label for="country">country</label>
<input type="text" id="country" class="form-control" formControlName="country">
<button type="submit" class="btn btn-primary" [disabled]="!myForm.valid">Sign Up</button>


export class Heatmap {
constructor(public name: string, public data: string, public country: string){}

The problem:

Each time I submit my form my server restarts automatically with no data logged, and doesn't give me time to look at any errors being consoled.

The only error I get is output from gulp -

error TS2339: Property 'sendData' does not exist on type 'HeatmapService'.

Hope someone can help!


When you submit your form, you call this.heatService.sendData(heatmap).... in you onSubmit() function.

If you've pasted the whole HeatmapService, there is no sendData method. That's exactly what the error says.

Either create this method or copy/paste it into your question.