-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added books.component logic and boilerplate books template
- Loading branch information
1 parent
82769b7
commit d008c4d
Showing
2 changed files
with
24 additions
and
5 deletions.
There are no files selected for viewing
10 changes: 9 additions & 1 deletion
10
angular-resources-page/src/app/pages/books/books.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,9 @@ | ||
<p>books works!</p> | ||
<div class="container mx-auto mt-8"> | ||
<h1 class="text-2xl font-bold mb-4">Books</h1> | ||
<ul class="list-disc pl-6 space-y-2"> | ||
<li *ngFor="let book of books"> | ||
<a [href]="book.link" target="_blank">{{ book.title }}</a> by {{ book.author }} | ||
</li> | ||
</ul> | ||
</div> | ||
|
19 changes: 15 additions & 4 deletions
19
angular-resources-page/src/app/pages/books/books.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,26 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { HttpClient } from '@angular/common/http'; | ||
|
||
interface Book { | ||
id: string; | ||
title: string; | ||
author: string; | ||
link: string; | ||
} | ||
|
||
@Component({ | ||
selector: 'app-books', | ||
templateUrl: './books.component.html', | ||
styleUrls: ['./books.component.css'] | ||
styleUrls: ['./books.component.scss'], | ||
}) | ||
export class BooksComponent implements OnInit { | ||
books: Book[] = []; | ||
|
||
constructor() { } | ||
constructor(private http: HttpClient) {} | ||
|
||
ngOnInit(): void { | ||
ngOnInit() { | ||
this.http | ||
.get<Book[]>('http://localhost:8080/api/books') | ||
.subscribe((data) => (this.books = data)); | ||
} | ||
|
||
} |