Skip to content

Commit f253c80

Browse files
committed
feat: show selected quantity when navigating back from the checkout step to the quantity step
1 parent 543770b commit f253c80

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

apps/signal/56-forms-and-signal/src/app/order.component.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
ChangeDetectionStrategy,
33
Component,
44
computed,
5+
effect,
56
input,
67
} from '@angular/core';
78
import { 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
}

0 commit comments

Comments
 (0)