Skip to content

Commit f4b7742

Browse files
exercise 5 - Templates - No image
1 parent 0ccd4c3 commit f4b7742

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed
107 KB
Loading

itenium-socks/src/app/socks/shop.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ <h2>
2727
<div class="box">
2828
<a href="/socks/{{ sock.id }}">
2929
<div class="img-box">
30-
<img src="sock-images/Socks-{{ sock.brand }}-{{ sock.variant }}.png" />
30+
<img src="sock-images/Socks-{{ sock.brand }}-{{ sock.variant }}.png" (error)="onImageError($event)" />
3131
</div>
3232
<div class="detail-box">
3333
<h6>{{ sock.name }}</h6>

itenium-socks/src/app/socks/shop.component.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export class ShopComponent {
2323
public currentPageSubject = new BehaviorSubject<number>(1);
2424
public pageSize = 10;
2525

26+
placeholderImageUrl = 'images/placeholder.jpg';
27+
2628
constructor(private socksService: SocksService) {}
2729

2830
ngOnInit(): void {
@@ -75,4 +77,7 @@ export class ShopComponent {
7577
this.currentPageSubject.next(page);
7678
}
7779

80+
onImageError(event: Event) {
81+
(event.target as HTMLImageElement).src = this.placeholderImageUrl;
82+
}
7883
}

0 commit comments

Comments
 (0)