-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathbook.component.ts
More file actions
38 lines (34 loc) · 1.23 KB
/
book.component.ts
File metadata and controls
38 lines (34 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { Component } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Resource } from 'ngx-jsonapi';
import { AuthorsService } from '../../authors/authors.service';
import { BooksService, Book } from './../books.service';
import { PhotosService } from '../../photos/photos.service';
@Component({
selector: 'demo-book',
standalone: false,
templateUrl: './book.component.html'
})
export class BookComponent {
public book: Book;
public constructor(
protected authorsService: AuthorsService,
protected booksService: BooksService,
protected photosService: PhotosService,
private route: ActivatedRoute
) {
route.params.subscribe(({ id }) => {
booksService.get(id, { include: ['author', 'photos'] }).subscribe(
(book) => {
this.book = book;
console.log('success book', this.book);
},
(error) => console.log('error books controll', error)
);
});
}
public getAuthorName(book: Resource): string {
const data: Resource = <Resource>book.relationships.author.data;
return data.attributes ? data.attributes.name : '';
}
}