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, );