When attempting to call my API using HttpModule, an error is being thrown upon starting the server (please refer to the screenshot). Error Image
The error arises when I try to make a call to the API from the service using Http.post method.
Here is my app.module.ts:
import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';
import {AppComponent} from './app.component';
import {HeaderComponent} from './header/header.component';
import {AuthComponent} from './auth/auth.component';
import {MarksComponent} from './marks/marks.component';
import {SigninComponent} from './auth/signin/signin.component';
import {SignupComponent} from './auth/signup/signup.component';
import {FormsModule} from '@angular/forms';
import {AppRoutingModule} from './app-routing.module';
import {AuthService} from './auth/auth.service';
import {HttpModule} from '@angular/http';
@NgModule({
declarations: [
AppComponent,
HeaderComponent,
AuthComponent,
MarksComponent,
SigninComponent,
SignupComponent
],
imports: [
BrowserModule,
FormsModule,
AppRoutingModule,
HttpModule
],
providers: [AuthService],
bootstrap: [AppComponent]
})
export class AppModule {
}
This is my service:
import {Router} from '@angular/router';
import {Injectable} from '@angular/core';
import {Http} from '@angular/http';
@Injectable()
export class AuthService {
constructor(private router: Router, private http: Http) {
}
signUpUser(firstName: string, lastName: string, email: string, password:
string) {
const body: [] = [firstName, lastName, email, password];
return this.http.post('http://localhost:3000/auth/signup', body).map(data
=> {
data = data.json();
return data;
});
}
}