Edit: read the part at the end of the question!
I get this error:

My service code:
import { Http, Response, Headers } from "@angular/http"; import { Injectable } from "@angular/core"; import 'rxjs/add/operator/map'; import 'rxjs/add/operator/catch'; import { Observable } from "rxjs"; import { Client } from "./client.model"; @Injectable() export class ClientService { private clients: Client[] = []; constructor(private http: Http){} addClient(client: Client) { this.clients.push(client); const body = JSON.stringify(client); const headers = new Headers({'Content-Type': 'application/json'}); return this.http.post('http://localhost:3000/client', body, {headers: headers}) .map((response: Response) => response.json()) .catch((error: Response) => Observable.throw(error.json())); } getClients() { return this.clients; } deleteClient(client: Client) { } }
And in my component, I have this send function:
onSubmit(form: NgForm) { let email = form.value.email; let password = form.value.password; let firstName = form.value.firstName; let lastName = form.value.lastName; const client = new Client(email, password, firstName, lastName); this.clientService.addClient(client) .subscribe( data => console.log(data), error => console.error(error) ); form.resetForm(); }
There are similar errors here and. The answer should always include rxjs functions, but I'm doing it, so I'm not quite sure why I get this error.
Edit:
Thus, the actual problem was not this function, but the missing "/" in front of my route in the main app.js. After that, the problem disappeared.
Zoker source share