- @for (housingLocation of housingLocationList; track housingLocation.id) {
+ @for (housingLocation of filteredLocationList; track housingLocation.id) {
diff --git a/src/app/home/home.component.ts b/src/app/home/home.component.ts
index 9bb1a30..a199f51 100644
--- a/src/app/home/home.component.ts
+++ b/src/app/home/home.component.ts
@@ -2,12 +2,14 @@ import {Component, inject} from '@angular/core';
import {HousingLocationComponent} from '../housing-location/housing-location.component';
import {HousingLocation} from '../housing-location';
import {HousingService} from '../housing.service';
+import {FormsModule} from '@angular/forms';
@Component({
selector: 'app-home',
standalone: true,
imports: [
- HousingLocationComponent
+ HousingLocationComponent,
+ FormsModule
],
templateUrl: './home.component.html',
styleUrl: './home.component.css'
@@ -15,8 +17,19 @@ import {HousingService} from '../housing.service';
export class HomeComponent {
housingLocationList: HousingLocation[] = [];
housingService: HousingService = inject(HousingService);
+ filteredLocationList: HousingLocation[] = [];
constructor() {
this.housingLocationList = this.housingService.getAllHousingLocations();
+ this.filteredLocationList = this.housingLocationList;
+ }
+
+ filterResults(text: string) {
+ if (!text) {
+ this.filteredLocationList = this.housingLocationList;
+ return;
+ }
+
+ this.filteredLocationList = this.housingLocationList.filter((housingLocation) => housingLocation?.city.toLowerCase().includes(text.toLowerCase()),);
}
}