Skip to content

Commit 1dca3ab

Browse files
BaggersIOrobinboehm
authored andcommitted
Create an observable
1 parent 0a7c2e6 commit 1dca3ab

File tree

2 files changed

+6
-43
lines changed

2 files changed

+6
-43
lines changed

src/app/book-list/book-list.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class BookListComponent implements OnInit {
1313

1414
constructor(private bookService: BookDataService) {
1515

16-
this.books = this.bookService.getBooks();
16+
this.bookService.getBooks().subscribe(books => this.books = books);
1717
}
1818

1919
ngOnInit() {
Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,16 @@
11
import { Injectable } from '@angular/core';
22
import { Book } from './book';
3+
import { HttpClient } from '@angular/common/http';
4+
import { Observable } from 'rxjs';
35

46
@Injectable()
57
export class BookDataService {
68

7-
private books: Book[] = [
8-
{
9-
"title": "Design Patterns",
10-
"subtitle": "Elements of Reusable Object-Oriented Software",
11-
"isbn": "978-0-20163-361-0",
12-
"abstract": "Capturing a wealth of experience about the design of object-oriented software, four top-notch designers present a catalog of simple and succinct solutions to commonly occurring design problems. Previously undocumented, these 23 patterns allow designers to create more flexible, elegant, and ultimately reusable designs without having to rediscover the design solutions themselves.",
13-
"numPages": 395,
14-
"author": "Erich Gamma / Richard Helm / Ralph E. Johnson / John Vlissides",
15-
"publisher": {
16-
"name": "Addison-Wesley",
17-
"url": "http://www.addison-wesley.de/"
18-
}
19-
},
20-
{
21-
"title": "REST und HTTP",
22-
"subtitle": "Entwicklung und Integration nach dem Architekturstil des Web",
23-
"isbn": "978-3-86490-120-1",
24-
"abstract": "Das Buch bietet eine theoretisch fundierte, vor allem aber praxistaugliche Anleitung zum professionellen Einsatz von RESTful HTTP. Es beschreibt den Architekturstil REST (Representational State Transfer) und seine Umsetzung im Rahmen der Protokolle des World Wide Web (HTTP, URIs und andere).",
25-
"numPages": 330,
26-
"author": "Stefan Tilkov / Martin Eigenbrodt / Silvia Schreier / Oliver Wolf",
27-
"publisher": {
28-
"name": "dpunkt.verlag",
29-
"url": "http://dpunkt.de/"
30-
}
31-
},
32-
{
33-
"title": "Eloquent JavaScript",
34-
"subtitle": "A Modern Introduction to Programming",
35-
"isbn": "978-1-59327-584-6",
36-
"abstract": "JavaScript lies at the heart of almost every modern web application, from social apps to the newest browser-based games. Though simple for beginners to pick up and play with, JavaScript is a flexible, complex language that you can use to build full-scale applications.",
37-
"numPages": 472,
38-
"author": "Marijn Haverbeke",
39-
"publisher": {
40-
"name": "No Starch Press",
41-
"url": "https://www.nostarch.com/"
42-
}
43-
}
44-
];
45-
46-
constructor() {
9+
constructor(private http: HttpClient) {
4710
}
4811

49-
getBooks(): Book[] {
50-
return this.books;
12+
getBooks(): Observable<Book[]> {
13+
return this.http.get<Book[]>('http://localhost:4730/books')
5114
}
5215

5316
}

0 commit comments

Comments
 (0)