import { Injectable, Inject } from '@angular/core'; //import { HttpClient, HttpParams, HttpRequest} from "@angular/common/http"; import { Http, Response, Headers, RequestOptions, HttpModule } from '@angular/http'; import 'rxjs/add/operator/map'; import 'rxjs/add/operator/catch'; import 'rxjs/add/observable/throw'; import { User } from '../UpdateProfile/datamodel'; import 'rxjs/add/operator/do'; import { Observable } from 'rxjs/Observable'; import { GlobalService } from '../../Shared/global'; @Injectable() export class UserService { constructor(private http: Http, private commonService: GlobalService ) { } GetUserById() { return this.http.get(this.commonService.resourceBaseUrl + "/api/GetUserProfile/1") .map(this.extractData) .catch((res: Response) => this.handleError(res));; } UpdateUserProfileById(obj: User) { //let options = new RequestOptions({ headers: this.headers }); return this.http.post(this.commonService.resourceBaseUrl + "/api/UpdateProfile", obj) .map(this.extractData) .catch((res: Response) => this.handleError(res)); } extractData(res: Response) { //debugger; let body = res.json(); return body; } handleError(error: any) { // In a real world app, we might use a remote logging infrastructure // We'd also dig deeper into the error to get a better message let errMsg = (error.message) ? error.message : error.status ? `${error.status} - ${error.statusText}` : 'Server error'; console.error(errMsg); // log to console instead return Observable.throw(errMsg); } ////public GetUserById(url: string): Observable { //// return this._http.get(url) //// .map((response: Response) => response.json()) //// .do(data => console.log("All: " + JSON.stringify(data))) //// .catch(this.handleError); ////} //// private handleError(error: Response) { //// console.error(error); //// return Observable.throw(error.json().error || 'Server error'); //// } }