From 8efd15a075bb214e97a03eb3c0ef59e5971beba0 Mon Sep 17 00:00:00 2001
From: Phan Huy Tran
Date: Wed, 13 Nov 2024 10:30:28 +0100
Subject: [PATCH] Form submit
---
src/app/details/details.component.html | 51 ++++++++++++++++++++++++++
src/app/details/details.component.ts | 19 +++++++++-
src/app/housing.service.ts | 4 ++
3 files changed, 73 insertions(+), 1 deletion(-)
diff --git a/src/app/details/details.component.html b/src/app/details/details.component.html
index c1c4c4c..72b2a16 100644
--- a/src/app/details/details.component.html
+++ b/src/app/details/details.component.html
@@ -38,4 +38,55 @@
+
+
diff --git a/src/app/details/details.component.ts b/src/app/details/details.component.ts
index 4961512..e4898d6 100644
--- a/src/app/details/details.component.ts
+++ b/src/app/details/details.component.ts
@@ -2,11 +2,14 @@ import {Component, inject} from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {HousingService} from '../housing.service';
import {HousingLocation} from '../housing-location';
+import {FormControl, FormGroup, ReactiveFormsModule} from '@angular/forms';
@Component({
selector: 'app-details',
standalone: true,
- imports: [],
+ imports: [
+ ReactiveFormsModule
+ ],
templateUrl: './details.component.html',
styleUrl: './details.component.css'
})
@@ -15,8 +18,22 @@ export class DetailsComponent {
housingService = inject(HousingService);
housingLocation: HousingLocation | undefined;
+ applyForm = new FormGroup({
+ firstName: new FormControl(''),
+ lastName: new FormControl(''),
+ email: new FormControl(''),
+ });
+
constructor() {
const housingLocationId = Number(this.route.snapshot.params['id']);
this.housingLocation = this.housingService.getHousingLocationById(housingLocationId);
}
+
+ submitApplication() {
+ this.housingService.submitApplication(
+ this.applyForm.value.firstName ?? '',
+ this.applyForm.value.lastName ?? '',
+ this.applyForm.value.email ?? '',
+ );
+ }
}
diff --git a/src/app/housing.service.ts b/src/app/housing.service.ts
index 9b1cee2..2ab56e3 100644
--- a/src/app/housing.service.ts
+++ b/src/app/housing.service.ts
@@ -105,4 +105,8 @@ export class HousingService {
getHousingLocationById(id: number): HousingLocation | undefined {
return this.housingLocationList.find((housingLocation) => housingLocation.id === id);
}
+
+ submitApplication(firstName: string, lastName: string, email: string) {
+ console.log(`Homes application received: firstName: ${firstName}, lastName: ${lastName}, email: ${email}.`,);
+ }
}