Last active
November 30, 2019 09:37
-
-
Save NishuGoel/a3a01c5d1ca091ee5105d293ee59ceff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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