|
1 |
| -import { Component, inject, OnInit } from '@angular/core'; |
2 |
| -import { CurrencyPipe, NgIf } from '@angular/common'; |
3 | 1 | import { injectActivatedRoute } from '@analogjs/router';
|
| 2 | +import { CurrencyPipe } from '@angular/common'; |
4 | 3 | import { HttpClient } from '@angular/common/http';
|
| 4 | +import { Component, inject, OnInit } from '@angular/core'; |
5 | 5 | import { catchError, of } from 'rxjs';
|
6 | 6 |
|
7 |
| -import { Product } from '../products'; |
8 | 7 | import { CartService } from '../cart.service';
|
| 8 | +import { Product } from '../products'; |
9 | 9 |
|
10 | 10 | @Component({
|
11 | 11 | selector: 'app-product-details',
|
12 |
| - standalone: true, |
13 |
| - imports: [NgIf, CurrencyPipe], |
| 12 | + imports: [CurrencyPipe], |
14 | 13 | template: `
|
15 | 14 | <h2>Product Details</h2>
|
16 | 15 |
|
17 |
| - <div *ngIf="product"> |
| 16 | + @if ( product ) { |
| 17 | +
|
| 18 | + <div> |
18 | 19 | <h3>{{ product.name }}</h3>
|
19 | 20 | <h4>{{ product.price | currency }}</h4>
|
20 | 21 | <p>{{ product.description }}</p>
|
21 | 22 | <button type="button" (click)="addToCart(product)">Buy</button>
|
22 | 23 | </div>
|
| 24 | + } |
23 | 25 | `,
|
24 | 26 | })
|
25 | 27 | export default class ProductDetailsComponent implements OnInit {
|
26 |
| - private route = injectActivatedRoute(); |
27 |
| - private cartService = inject(CartService); |
28 |
| - private http = inject(HttpClient); |
| 28 | + private readonly route = injectActivatedRoute(); |
| 29 | + private readonly cartService = inject(CartService); |
| 30 | + private readonly http = inject(HttpClient); |
29 | 31 |
|
30 | 32 | product: Product | undefined;
|
31 | 33 |
|
|
0 commit comments