Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import { Injectable } from '@angular/core';
import { Http, URLSearchParams } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';
import { User } from '../model/user';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
@Injectable()
export class UserService {
constructor(private http: Http) {
}
insertNewUser(user:User): Observable<any>{
return this.http.post("http://localhost:3000/insertUser", user)
.map((res:any) => {
return res.json();
})
.catch((error:any) => {
return Observable.throw(error.json ? error.json().error : error || 'Server error')
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment