Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Injectable } from "@angular/core";
  2. import { Http, Headers, Response } from "@angular/http";
  3. import { Observable } from "rxjs/Rx";
  4. import "rxjs/add/operator/do";
  5. import "rxjs/add/operator/map";
  6.  
  7. import { User } from "./user";
  8. import { Config } from "../config";
  9.  
  10. @Injectable()
  11. export class UserService {
  12.   constructor(private http: Http) {}
  13.  
  14.   register(user: User) {
  15.     let headers = new Headers();
  16.     headers.append("Content-Type", "application/json");
  17.  
  18.     return this.http.post(
  19.       Config.apiUrl + "Users",
  20.       JSON.stringify({
  21.         Username: user.email,
  22.         Email: user.email,
  23.         Password: user.password
  24.       }),
  25.       { headers: headers }
  26.     )
  27.     .catch(this.handleErrors);
  28.   }
  29.  
  30.   handleErrors(error: Response) {
  31.     console.log(JSON.stringify(error.json()));
  32.     return Observable.throw(error);
  33.   }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement