Skip to content

Instantly share code, notes, and snippets.

@NishuGoel
Last active November 30, 2019 09:37
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 NishuGoel/a3a01c5d1ca091ee5105d293ee59ceff to your computer and use it in GitHub Desktop.
Save NishuGoel/a3a01c5d1ca091ee5105d293ee59ceff to your computer and use it in GitHub Desktop.
import { Injectable } from '@angular/core';
import {HttpClient, HttpHeaders} from '@angular/common/http';
import {Observable, throwError} from 'rxjs';
import { tap, catchError } from 'rxjs/operators';
import {User} from './user-data';
@Injectable({
providedIn: 'root'
})
export class DataService {
apiurl = 'api/users'; // Our created Data can be accessed here at api/users
headers = new HttpHeaders().set('Content-Type', 'application/json').set('Accept', 'application/json');
httpOptions = {
headers: this.headers
};
constructor(private http: HttpClient) { } //Injecting HTTP service to communicate with the data
private handleError(error: any) {
console.error(error); //Created a function to handle and log errors, in case
return throwError(error);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment