@@ -1,7 +1,8 @@
|
|
1 |
-
import { Component, signal } from '@angular/core';
|
2 |
|
3 |
import { Book } from '../../shared/book';
|
4 |
import { BookItem } from '../book-item/book-item';
|
|
|
5 |
|
6 |
@Component({
|
7 |
selector: 'app-book-list',
|
@@ -10,30 +11,13 @@ import { BookItem } from '../book-item/book-item';
|
|
10 |
styleUrl: './book-list.scss',
|
11 |
})
|
12 |
export class BookList {
|
|
|
|
|
13 |
readonly books = signal<Book[]>([]);
|
14 |
readonly likedBooks = signal<Book[]>([]);
|
15 |
|
16 |
constructor() {
|
17 |
-
this.books.set(
|
18 |
-
{
|
19 |
-
isbn: '12345',
|
20 |
-
title: 'Tierisch gut kochen',
|
21 |
-
authors: ['Mrs Chimp', 'Mr Gorilla'],
|
22 |
-
subtitle: 'Rezepte von Affe bis Zebra',
|
23 |
-
imageUrl: 'https://cdn.ng-buch.de/kochen.png',
|
24 |
-
description: 'Immer lecker und gut',
|
25 |
-
createdAt: new Date().toISOString(),
|
26 |
-
},
|
27 |
-
{
|
28 |
-
isbn: '67890',
|
29 |
-
title: 'Backen mit Affen',
|
30 |
-
subtitle: 'Bananenbrot und mehr',
|
31 |
-
authors: ['Orang Utan'],
|
32 |
-
imageUrl: 'https://cdn.ng-buch.de/backen.png',
|
33 |
-
description: 'Tolle Backtipps für Mensch und Tier',
|
34 |
-
createdAt: new Date().toISOString(),
|
35 |
-
},
|
36 |
-
]);
|
37 |
}
|
38 |
|
39 |
addLikedBook(newLikedBook: Book) {
|
|
|
1 |
+
import { Component, inject, signal } from '@angular/core';
|
2 |
|
3 |
import { Book } from '../../shared/book';
|
4 |
import { BookItem } from '../book-item/book-item';
|
5 |
+
import { BookStore } from '../../shared/book-store';
|
6 |
|
7 |
@Component({
|
8 |
selector: 'app-book-list',
|
|
|
11 |
styleUrl: './book-list.scss',
|
12 |
})
|
13 |
export class BookList {
|
14 |
+
#store = inject(BookStore);
|
15 |
+
|
16 |
readonly books = signal<Book[]>([]);
|
17 |
readonly likedBooks = signal<Book[]>([]);
|
18 |
|
19 |
constructor() {
|
20 |
+
this.books.set(this.#store.getBookList());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
}
|
22 |
|
23 |
addLikedBook(newLikedBook: Book) {
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { Injectable } from '@angular/core';
|
2 |
+
|
3 |
+
import { Book } from './book';
|
4 |
+
|
5 |
+
@Injectable({
|
6 |
+
providedIn: 'root'
|
7 |
+
})
|
8 |
+
export class BookStore {
|
9 |
+
|
10 |
+
#books: Book[] = [
|
11 |
+
{
|
12 |
+
isbn: '12345',
|
13 |
+
title: 'Tierisch gut kochen',
|
14 |
+
authors: ['Mrs Chimp', 'Mr Gorilla'],
|
15 |
+
subtitle: 'Rezepte von Affe bis Zebra',
|
16 |
+
imageUrl: 'https://cdn.ng-buch.de/kochen.png',
|
17 |
+
description: 'Immer lecker und gut',
|
18 |
+
createdAt: new Date().toISOString()
|
19 |
+
},
|
20 |
+
{
|
21 |
+
isbn: '67890',
|
22 |
+
title: 'Backen mit Affen',
|
23 |
+
subtitle: 'Bananenbrot und mehr',
|
24 |
+
authors: ['Orang Utan'],
|
25 |
+
imageUrl: 'https://cdn.ng-buch.de/backen.png',
|
26 |
+
description: 'Tolle Backtipps für Mensch und Tier',
|
27 |
+
createdAt: new Date().toISOString()
|
28 |
+
}
|
29 |
+
];
|
30 |
+
|
31 |
+
getBookList(): Book[] {
|
32 |
+
return this.#books;
|
33 |
+
}
|
34 |
+
}
|