Skip to content

Instantly share code, notes, and snippets.

@NMZivkovic
Created October 8, 2017 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NMZivkovic/369f32150e0795c5c0b866a7f37f8e50 to your computer and use it in GitHub Desktop.
Save NMZivkovic/369f32150e0795c5c0b866a7f37f8e50 to your computer and use it in GitHub Desktop.
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