I need help connecting Angular 2 to Express. I've successfully set up and tested the server endpoint using Postman (it seems that the content type needs to be x-www-form-urlencoded for it to work), but I'm unsure if there are any specific configurations in Angular 2 to handle that request. My suspicion is that the content-type might be incorrect.
form.ts
import {Component, ViewEncapsulation} from "angular2/core";
import {FORM_DIRECTIVES, FormBuilder, ControlGroup, AbstractControl, Validators, Control} from "angular2/common";
import { Http } from "angular2/http";
@Component({
selector: "parameters-form",
directives: [FORM_DIRECTIVES],
templateUrl: "dev/form.template.html"
})
export class ParametersForm {
myForm: ControlGroup;
systemParameters: AbstractControl;
param: AbstractControl;
liftOperator: AbstractControl;
restrictOperator: AbstractControl;
xInitial: AbstractControl;
system_arr: number[];
param_arr: number[];
restrict_arr: number[];
lift_arr: number[];
xinitial_arr: number[];
constructor(fb: FormBuilder, private _http: Http) {
// Additional code...
}
// More code...
server.js
var express = require('express');
var bodyParser = require('body-parser')
var cors = require('cors');
var app = express();
app.use(cors());
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
// Rest of the server code...