finish all getall into table
This commit is contained in:
56
src/app/components/book-table/book-table.ts
Normal file
56
src/app/components/book-table/book-table.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import {Component, inject, OnInit, signal} from '@angular/core'; // Importation de la fonction input() et des components
|
||||
import {Modal} from "../modal/modal";
|
||||
import {NzButtonComponent} from "ng-zorro-antd/button";
|
||||
import {BooksService, GetBookDto} from "../../services/api";
|
||||
import {NzNotificationService} from "ng-zorro-antd/notification";
|
||||
import {firstValueFrom} from "rxjs";
|
||||
import {NzTableComponent} from "ng-zorro-antd/table";
|
||||
import {NzDividerComponent} from "ng-zorro-antd/divider";
|
||||
import {UpdateBook} from "../update-book/update-book";
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-table',
|
||||
imports: [
|
||||
Modal,
|
||||
NzButtonComponent,
|
||||
NzTableComponent,
|
||||
NzDividerComponent,
|
||||
UpdateBook,
|
||||
],
|
||||
templateUrl: './book-table.html',
|
||||
styleUrl: './book-table.css',
|
||||
})
|
||||
export class BookTable implements OnInit {
|
||||
private booksService = inject(BooksService);
|
||||
private notificationService = inject(NzNotificationService)
|
||||
|
||||
books = signal<GetBookDto[]>([]);
|
||||
|
||||
booksLoading = signal<boolean>(false);
|
||||
|
||||
async ngOnInit() {
|
||||
await this.fetchbooks();
|
||||
}
|
||||
|
||||
async fetchbooks() {
|
||||
this.booksLoading.set(true)
|
||||
|
||||
try {
|
||||
const books = await firstValueFrom(this.booksService.getAllBooksEndpoint());
|
||||
|
||||
this.books.set(books);
|
||||
|
||||
|
||||
} catch (e) {
|
||||
this.notificationService.error(
|
||||
'Erreur',
|
||||
'Erreur de communication avec l\'API'
|
||||
)
|
||||
}
|
||||
this.booksLoading.set(false)
|
||||
}
|
||||
|
||||
delete() {
|
||||
return
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user