From dd2c4f54d40342eb57dee42c7d2bacb372040eb8 Mon Sep 17 00:00:00 2001 From: Yoni ZANA Date: Wed, 22 Oct 2025 13:12:16 +0200 Subject: [PATCH] feat(order): bind quantity from route query params --- .../56-forms-and-signal/src/app/order.component.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/signal/56-forms-and-signal/src/app/order.component.ts b/apps/signal/56-forms-and-signal/src/app/order.component.ts index 2b03ba814..e24e16d1d 100644 --- a/apps/signal/56-forms-and-signal/src/app/order.component.ts +++ b/apps/signal/56-forms-and-signal/src/app/order.component.ts @@ -2,11 +2,12 @@ import { ChangeDetectionStrategy, Component, computed, + inject, input, } from '@angular/core'; import { toSignal } from '@angular/core/rxjs-interop'; import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms'; -import { RouterLink } from '@angular/router'; +import { ActivatedRoute, RouterLink } from '@angular/router'; import { products } from './products'; @Component({ @@ -54,11 +55,16 @@ import { products } from './products'; changeDetection: ChangeDetectionStrategy.OnPush, }) export default class OrderComponent { + private route = inject(ActivatedRoute); + + quantityBinded = this.route.snapshot.queryParams['quantity'] || 1; + form = new FormGroup({ - quantity: new FormControl(1, { nonNullable: true }), + quantity: new FormControl(this.quantityBinded, { nonNullable: true }), }); productId = input('1'); + price = computed( () => products.find((p) => p.id === this.productId())?.price ?? 0, );