This commit is contained in:
2025-11-04 11:32:02 +01:00
parent 28edfef8bf
commit 40ac21b234
2 changed files with 53 additions and 22 deletions

View File

@@ -2,8 +2,10 @@ import {Component, inject} from '@angular/core';
import {ActivatedRoute} from '@angular/router'; import {ActivatedRoute} from '@angular/router';
import {HousingService} from '../housing'; import {HousingService} from '../housing';
import {HousingLocationInfo} from '../housinglocation'; import {HousingLocationInfo} from '../housinglocation';
import {FormControl, FormGroup, ReactiveFormsModule} from '@angular/forms';
@Component({ @Component({
selector: 'app-details', selector: 'app-details',
imports: [ReactiveFormsModule],
template: ` template: `
<article> <article>
<img <img
@@ -24,6 +26,18 @@ import {HousingLocationInfo} from '../housinglocation';
<li>Does this location have laundry: {{ housingLocation?.laundry }}</li> <li>Does this location have laundry: {{ housingLocation?.laundry }}</li>
</ul> </ul>
</section> </section>
<section class="listing-apply">
<h2 class="section-heading">Apply now to live here</h2>
<form [formGroup]="applyForm" (submit)="submitApplication()">
<label for="first-name">First Name</label>
<input id="first-name" type="text" formControlName="firstName" />
<label for="last-name">Last Name</label>
<input id="last-name" type="text" formControlName="lastName" />
<label for="email">Email</label>
<input id="email" type="email" formControlName="email" />
<button type="submit" class="primary">Apply now</button>
</form>
</section>
</article> </article>
`, `,
styleUrls: ['./details.css'], styleUrls: ['./details.css'],
@@ -32,8 +46,20 @@ export class Details {
route: ActivatedRoute = inject(ActivatedRoute); route: ActivatedRoute = inject(ActivatedRoute);
housingService = inject(HousingService); housingService = inject(HousingService);
housingLocation: HousingLocationInfo | undefined; housingLocation: HousingLocationInfo | undefined;
applyForm = new FormGroup({
firstName: new FormControl(''),
lastName: new FormControl(''),
email: new FormControl(''),
});
constructor() { constructor() {
const housingLocationId = Number(this.route.snapshot.params['id']); const housingLocationId = parseInt(this.route.snapshot.params['id'], 10);
this.housingLocation = this.housingService.getHousingLocationById(housingLocationId); this.housingLocation = this.housingService.getHousingLocationById(housingLocationId);
} }
submitApplication() {
this.housingService.submitApplication(
this.applyForm.value.firstName ?? '',
this.applyForm.value.lastName ?? '',
this.applyForm.value.email ?? '',
);
}
} }

View File

@@ -113,4 +113,9 @@ export class HousingService {
getHousingLocationById(id: number): HousingLocationInfo | undefined { getHousingLocationById(id: number): HousingLocationInfo | undefined {
return this.housingLocationList.find((housingLocation) => housingLocation.id === id); 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}.`,
);
}
} }