@@ -1,5 +1,6 @@
|
|
1 |
import { CommonModule } from '@angular/common';
|
2 |
import { NgModule } from '@angular/core';
|
|
|
3 |
|
4 |
import { AppRoutingModule } from './app-routing.module.one-app';
|
5 |
import { AppComponent } from './app.component';
|
@@ -18,6 +19,7 @@
|
|
18 |
],
|
19 |
imports: [
|
20 |
CommonModule,
|
|
|
21 |
AppRoutingModule
|
22 |
],
|
23 |
providers: [],
|
1 |
import { CommonModule } from '@angular/common';
|
2 |
import { NgModule } from '@angular/core';
|
3 |
+
import { HttpClientModule } from '@angular/common/http';
|
4 |
|
5 |
import { AppRoutingModule } from './app-routing.module.one-app';
|
6 |
import { AppComponent } from './app.component';
|
19 |
],
|
20 |
imports: [
|
21 |
CommonModule,
|
22 |
+
HttpClientModule,
|
23 |
AppRoutingModule
|
24 |
],
|
25 |
providers: [],
|
@@ -1,4 +1,4 @@
|
|
1 |
-
<div *ngIf="book">
|
2 |
<h1>{{ book.title }}</h1>
|
3 |
<h3 *ngIf="book.subtitle">{{ book.subtitle }}</h3>
|
4 |
<div class="ui divider"></div>
|
@@ -29,4 +29,12 @@
|
|
29 |
<img *ngFor="let thumbnail of book.thumbnails"
|
30 |
[src]="thumbnail.url">
|
31 |
</div>
|
|
|
|
|
|
|
|
|
32 |
</div>
|
|
|
|
|
|
|
|
1 |
+
<div *ngIf="book; else loading">
|
2 |
<h1>{{ book.title }}</h1>
|
3 |
<h3 *ngIf="book.subtitle">{{ book.subtitle }}</h3>
|
4 |
<div class="ui divider"></div>
|
29 |
<img *ngFor="let thumbnail of book.thumbnails"
|
30 |
[src]="thumbnail.url">
|
31 |
</div>
|
32 |
+
<button class="ui tiny red labeled icon button"
|
33 |
+
(click)="removeBook()">
|
34 |
+
<i class="remove icon"></i> Buch löschen
|
35 |
+
</button>
|
36 |
</div>
|
37 |
+
|
38 |
+
<ng-template #loading>
|
39 |
+
<div class="ui active centered inline loader"></div>
|
40 |
+
</ng-template>
|
@@ -1,5 +1,5 @@
|
|
1 |
import { Component, OnInit } from '@angular/core';
|
2 |
-
import { ActivatedRoute } from '@angular/router';
|
3 |
|
4 |
import { Book } from '../shared/book';
|
5 |
import { BookStoreService } from '../shared/book-store.service';
|
@@ -14,15 +14,24 @@
|
|
14 |
|
15 |
constructor(
|
16 |
private bs: BookStoreService,
|
|
|
17 |
private route: ActivatedRoute
|
18 |
) { }
|
19 |
|
20 |
ngOnInit() {
|
21 |
const params = this.route.snapshot.paramMap;
|
22 |
-
this.
|
|
|
23 |
}
|
24 |
|
25 |
getRating(num: number) {
|
26 |
return new Array(num);
|
27 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
}
|
1 |
import { Component, OnInit } from '@angular/core';
|
2 |
+
import { ActivatedRoute, Router } from '@angular/router';
|
3 |
|
4 |
import { Book } from '../shared/book';
|
5 |
import { BookStoreService } from '../shared/book-store.service';
|
14 |
|
15 |
constructor(
|
16 |
private bs: BookStoreService,
|
17 |
+
private router: Router,
|
18 |
private route: ActivatedRoute
|
19 |
) { }
|
20 |
|
21 |
ngOnInit() {
|
22 |
const params = this.route.snapshot.paramMap;
|
23 |
+
this.bs.getSingle(params.get('isbn'))
|
24 |
+
.subscribe(b => this.book = b);
|
25 |
}
|
26 |
|
27 |
getRating(num: number) {
|
28 |
return new Array(num);
|
29 |
}
|
30 |
+
|
31 |
+
removeBook() {
|
32 |
+
if (confirm('Buch wirklich löschen?')) {
|
33 |
+
this.bs.remove(this.book.isbn)
|
34 |
+
.subscribe(res => this.router.navigate(['../'], { relativeTo: this.route }));
|
35 |
+
}
|
36 |
+
}
|
37 |
}
|
@@ -3,4 +3,10 @@
|
|
3 |
*ngFor="let b of books"
|
4 |
[book]="b"
|
5 |
[routerLink]="b.isbn"></bm-book-list-item>
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
</div>
|
3 |
*ngFor="let b of books"
|
4 |
[book]="b"
|
5 |
[routerLink]="b.isbn"></bm-book-list-item>
|
6 |
+
|
7 |
+
<div *ngIf="!books" class="ui active dimmer">
|
8 |
+
<div class="ui large text loader">Daten werden geladen...</div>
|
9 |
+
</div>
|
10 |
+
|
11 |
+
<p *ngIf="books && !books.length">Es wurden noch keine Bücher eingetragen.</p>
|
12 |
</div>
|
@@ -14,6 +14,6 @@
|
|
14 |
constructor(private bs: BookStoreService) { }
|
15 |
|
16 |
ngOnInit() {
|
17 |
-
this.books =
|
18 |
}
|
19 |
}
|
14 |
constructor(private bs: BookStoreService) { }
|
15 |
|
16 |
ngOnInit() {
|
17 |
+
this.bs.getAll().subscribe(res => this.books = res);
|
18 |
}
|
19 |
}
|
@@ -1,4 +1,6 @@
|
|
1 |
import { Injectable } from '@angular/core';
|
|
|
|
|
2 |
|
3 |
import { Book } from './book';
|
4 |
|
@@ -6,44 +8,24 @@
|
|
6 |
providedIn: 'root'
|
7 |
})
|
8 |
export class BookStoreService {
|
9 |
-
|
10 |
|
11 |
-
constructor
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
title: 'Angular',
|
16 |
-
authors: ['Ferdinand Malcher', 'Johannes Hoppe', 'Danny Koppenhagen'],
|
17 |
-
published: new Date(2019, 4, 30),
|
18 |
-
subtitle: 'Grundlagen, fortgeschrittene Themen und Best Practices - mit NativeScript und NgRx',
|
19 |
-
rating: 5,
|
20 |
-
thumbnails: [{
|
21 |
-
url: 'https://ng-buch.de/buch1.jpg',
|
22 |
-
title: 'Buchcover'
|
23 |
-
}],
|
24 |
-
description: 'Die Autoren führen Sie mit einem anspruchsvollen Beispielprojekt durch die Welt von Angular...'
|
25 |
-
},
|
26 |
-
{
|
27 |
-
isbn: '9783864903274',
|
28 |
-
title: 'React',
|
29 |
-
authors: ['Oliver Zeigermann', 'Nils Hartmann'],
|
30 |
-
published: new Date(2016, 6, 17),
|
31 |
-
subtitle: 'Die praktische Einführung in React, React Router und Redux',
|
32 |
-
rating: 3,
|
33 |
-
thumbnails: [{
|
34 |
-
url: 'https://ng-buch.de/buch2.jpg',
|
35 |
-
title: 'Buchcover'
|
36 |
-
}],
|
37 |
-
description: 'React ist ein JavaScript-Framework zur Entwicklung von Benutzeroberflächen...'
|
38 |
-
}
|
39 |
-
];
|
40 |
}
|
41 |
|
42 |
-
|
43 |
-
return this.
|
|
|
|
|
44 |
}
|
45 |
|
46 |
-
|
47 |
-
return this.
|
|
|
|
|
|
|
48 |
}
|
49 |
}
|
1 |
import { Injectable } from '@angular/core';
|
2 |
+
import { HttpClient } from '@angular/common/http';
|
3 |
+
import { Observable } from 'rxjs';
|
4 |
|
5 |
import { Book } from './book';
|
6 |
|
8 |
providedIn: 'root'
|
9 |
})
|
10 |
export class BookStoreService {
|
11 |
+
private api = 'https://api3.angular-buch.com';
|
12 |
|
13 |
+
constructor(private http: HttpClient) {}
|
14 |
+
|
15 |
+
getAll(): Observable<Book[]> {
|
16 |
+
return this.http.get<any[]>(`${this.api}/books`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
}
|
18 |
|
19 |
+
getSingle(isbn: string): Observable<Book> {
|
20 |
+
return this.http.get<any>(
|
21 |
+
`${this.api}/book/${isbn}`
|
22 |
+
);
|
23 |
}
|
24 |
|
25 |
+
remove(isbn: string): Observable<any> {
|
26 |
+
return this.http.delete(
|
27 |
+
`${this.api}/book/${isbn}`,
|
28 |
+
{ responseType: 'text' }
|
29 |
+
);
|
30 |
}
|
31 |
}
|