Skip to content

Commit 0a7c2e6

Browse files
BaggersIOrobinboehm
authored andcommitted
Create a BookData service
1 parent 961b532 commit 0a7c2e6

File tree

3 files changed

+61
-40
lines changed

3 files changed

+61
-40
lines changed

src/app/app.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { InfoBoxComponent } from './info-box/info-box.component';
88
import { MouseCursorComponent } from './mouse-cursor/mouse-cursor.component';
99
import { TitleBoxComponent } from './title-box/title-box.component';
1010
import { BookListComponent } from './book-list/book-list.component';
11+
import { BookDataService } from './shared/book-data.service';
1112

1213
@NgModule({
1314
declarations: [
@@ -22,7 +23,7 @@ import { BookListComponent } from './book-list/book-list.component';
2223
FormsModule,
2324
HttpClientModule
2425
],
25-
providers: [],
26+
providers: [BookDataService],
2627
bootstrap: [AppComponent]
2728
})
2829
export class AppModule { }

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

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Component, OnInit } from '@angular/core';
22
import { Book } from '../shared/book';
3+
import { BookDataService } from '../shared/book-data.service';
34

45
@Component({
56
selector: 'book-list',
@@ -8,46 +9,12 @@ import { Book } from '../shared/book';
89
})
910
export class BookListComponent implements OnInit {
1011

11-
books: [Book] = [
12-
{
13-
"title": "Design Patterns",
14-
"subtitle": "Elements of Reusable Object-Oriented Software",
15-
"isbn": "978-0-20163-361-0",
16-
"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.",
17-
"numPages": 395,
18-
"author": "Erich Gamma / Richard Helm / Ralph E. Johnson / John Vlissides",
19-
"publisher": {
20-
"name": "Addison-Wesley",
21-
"url": "http://www.addison-wesley.de/"
22-
}
23-
},
24-
{
25-
"title": "REST und HTTP",
26-
"subtitle": "Entwicklung und Integration nach dem Architekturstil des Web",
27-
"isbn": "978-3-86490-120-1",
28-
"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).",
29-
"numPages": 330,
30-
"author": "Stefan Tilkov / Martin Eigenbrodt / Silvia Schreier / Oliver Wolf",
31-
"publisher": {
32-
"name": "dpunkt.verlag",
33-
"url": "http://dpunkt.de/"
34-
}
35-
},
36-
{
37-
"title": "Eloquent JavaScript",
38-
"subtitle": "A Modern Introduction to Programming",
39-
"isbn": "978-1-59327-584-6",
40-
"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.",
41-
"numPages": 472,
42-
"author": "Marijn Haverbeke",
43-
"publisher": {
44-
"name": "No Starch Press",
45-
"url": "https://www.nostarch.com/"
46-
}
47-
}
48-
];
12+
books: Book[] = [];
4913

50-
constructor() { }
14+
constructor(private bookService: BookDataService) {
15+
16+
this.books = this.bookService.getBooks();
17+
}
5118

5219
ngOnInit() {
5320
}

src/app/shared/book-data.service.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { Injectable } from '@angular/core';
2+
import { Book } from './book';
3+
4+
@Injectable()
5+
export class BookDataService {
6+
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() {
47+
}
48+
49+
getBooks(): Book[] {
50+
return this.books;
51+
}
52+
53+
}

0 commit comments

Comments
 (0)