Skip to content
Snippets Groups Projects
Commit 2ed4c5f8 authored by pnogal's avatar pnogal
Browse files

Add data.service.ts

parent d2c1699b
No related branches found
No related tags found
No related merge requests found
import { identifierModuleUrl } from '@angular/compiler';
import { Injectable } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { Router } from '@angular/router';
import { Observable } from 'rxjs';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { ConfigService } from './config.service';
import { Response, ResponseContentType } from '@angular/http';
import { Observable } from 'rxjs';
import { catchError, map, tap } from 'rxjs/operators';
import { throwError } from 'rxjs';
@Injectable()
export class DataService {
private api: string;
private coursesUrl = 'https://dev.enroll.wisc.edu/api/planner/v1/degreePlan/519261/courses';
private log: any;
constructor(private http: HttpClientModule, private configService: ConfigService) {
constructor(private http: HttpClient, private configService: ConfigService) {
this.api = this.configService.apiUrl;
}
getCourseData() {
return this.http
.get(this.coursesUrl)
// .subscribe(
// data => console.log('data: ', data), // success path
// error => console.log('error: ', error) // error path
// );
.pipe(
map(this.extractData),
catchError(this.errorHandler)
);
}
private extractData(res: Response) {
return res.text() ? res.json() : {};
}
private errorHandler(error: Response) {
// console.error(error);
return throwError(error || 'Server Error');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment