Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Injectable } from "@angular/core";
- // import { Http, Headers, HttpModule, Response } from "@angular/http";
- import { HttpClient } from '@angular/common/http';
- import { Observable, throwError } from "rxjs";
- import { catchError, map, tap } from "rxjs/operators";
- import { User } from "./user.model";
- import { Config } from "../config";
- @Injectable()
- export class UserService {
- constructor(private http: HttpClient) { }
- register(user: User) {
- if (!user.email || !user.password) {
- return throwError("Please provide both an email address and password.");
- }
- return this.http.post(
- Config.apiUrl + "user/" + Config.appKey,
- JSON.stringify({
- username: user.email,
- email: user.email,
- password: user.password
- }),
- //{ headers: this.getCommonHeaders() }
- ).pipe(
- catchError(this.handleErrors)
- );
- }
- getCommonHeaders() {
- let headers = new Headers();
- headers.append("Content-Type", "application/json");
- headers.append("Authorization", Config.authHeader);
- return headers;
- }
- handleErrors(error: Response) {
- console.log(JSON.stringify(error.json()));
- return Observable.throw(error);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement