Files
cbsnexora/src/app/home/quote.service.ts
T
abhay_1806 fc7ae1d0ba feat: add app shell (angular-material)
Add app shell built using angular-material and flex-layout. Refractor
code due to configuration changes.

Fixes #52
2018-06-23 20:06:32 +05:30

32 lines
761 B
TypeScript

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, of } from 'rxjs';
import { map, catchError } from 'rxjs/operators';
const routes = {
quote: (c: RandomQuoteContext) => `/jokes/random?category=${c.category}`
};
export interface RandomQuoteContext {
// The quote's category: 'dev', 'explicit'...
category: string;
}
@Injectable()
export class QuoteService {
constructor(private httpClient: HttpClient) { }
getRandomQuote(context: RandomQuoteContext): Observable<string> {
return this.httpClient
.cache()
.get(routes.quote(context))
.pipe(
map((body: any) => body.value),
catchError(() => of('Error, could not load joke :-('))
);
}
}