1- import { AsyncPipe } from '@angular/common' ;
21import {
32 ChangeDetectionStrategy ,
43 Component ,
4+ effect ,
55 inject ,
6- Input ,
6+ input ,
77} from '@angular/core' ;
88import { CurrencyPipe } from './currency.pipe' ;
99import { CurrencyService } from './currency.service' ;
@@ -13,22 +13,23 @@ import { Product } from './product.model';
1313 // eslint-disable-next-line @angular-eslint/component-selector
1414 selector : 'tr[product-row]' ,
1515 template : `
16- <td>{{ productInfo.name }}</td>
17- <td>{{ productInfo.priceA | currency | async }}</td>
18- <td>{{ productInfo.priceB | currency | async }}</td>
19- <td>{{ productInfo.priceC | currency | async }}</td>
16+ <td>{{ productInfo() .name }}</td>
17+ <td>{{ productInfo() .priceA | currency }}</td>
18+ <td>{{ productInfo() .priceB | currency }}</td>
19+ <td>{{ productInfo() .priceC | currency }}</td>
2020 ` ,
21- imports : [ AsyncPipe , CurrencyPipe ] ,
21+ imports : [ CurrencyPipe ] ,
2222 providers : [ CurrencyService ] ,
2323 changeDetection : ChangeDetectionStrategy . OnPush ,
2424} )
2525export class ProductRowComponent {
26- protected productInfo ! : Product ;
26+ productInfo = input . required < Product > ( { alias : 'product' } ) ;
27+ currencyService = inject ( CurrencyService ) ;
2728
28- @Input ( { required : true } ) set product ( product : Product ) {
29- this . currencyService . updateCode ( product . currencyCode ) ;
30- this . productInfo = product ;
29+ constructor ( ) {
30+ effect ( ( ) => {
31+ const product = this . productInfo ( ) ;
32+ this . currencyService . updateCode ( product . currencyCode ) ;
33+ } ) ;
3134 }
32-
33- currencyService = inject ( CurrencyService ) ;
3435}
0 commit comments