I am trying to publish data for an internal Node js file from Angular. After submitting the form, the function is called:
cmdSubmit() : void
{
console.log(this.cli);
this.Cliservice.postdata(this.cli)
.then(clidata => this.clidata.push(clidata),
error => this.errorMessage = <any>error);
}
postdata function code:
postdata(obj: any): Promise<any> {
alert('hello');
let body = JSON.stringify({ obj });
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this.http.post(this.runUrl, body, options)
.map(this.extractData)
.catch(this.handleError);
}
private extractData(res: Response) {
let body = res.json();
return body.data || { };
}
private handleError (error: any) {
let errMsg = (error.message) ? error.message :
error.status ? '${error.status} - ${error.statusText}' : 'Server error';
console.error(errMsg);
return Observable.throw(errMsg);
}
}
But nothing happens here. I do not receive any error messages. Can you suggest anything about this?
source
share