File tree Expand file tree Collapse file tree
apps/signal/56-forms-and-signal/src/app Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22 ChangeDetectionStrategy ,
33 Component ,
44 computed ,
5+ effect ,
56 input ,
67} from '@angular/core' ;
78import { toSignal } from '@angular/core/rxjs-interop' ;
@@ -59,6 +60,8 @@ export default class OrderComponent {
5960 } ) ;
6061
6162 productId = input ( '1' ) ;
63+ quantityInput = input ( 1 , { alias : 'quantity' } ) ;
64+
6265 price = computed (
6366 ( ) => products . find ( ( p ) => p . id === this . productId ( ) ) ?. price ?? 0 ,
6467 ) ;
@@ -68,4 +71,14 @@ export default class OrderComponent {
6871 totalWithoutVat = computed ( ( ) => Number ( this . price ( ) ) * this . quantity ( ) ) ;
6972 vat = computed ( ( ) => this . totalWithoutVat ( ) * 0.21 ) ;
7073 total = computed ( ( ) => this . totalWithoutVat ( ) + this . vat ( ) ) ;
74+
75+ constructor ( ) {
76+ effect ( ( ) => {
77+ const quantity = this . quantityInput ( ) ;
78+
79+ if ( quantity ) {
80+ this . form . patchValue ( { quantity } ) ;
81+ }
82+ } ) ;
83+ }
7184}
You can’t perform that action at this time.
0 commit comments