This commit is contained in:
2025-11-04 11:39:53 +01:00
parent 40ac21b234
commit 61397de9e5
3 changed files with 21 additions and 12 deletions

View File

@@ -1,12 +1,10 @@
<section>
<form>
<input type="text" placeholder="Filter by city" />
<button class="primary" type="button">Search</button>
<form><input type="text" placeholder="Filter by city" #filter/>
<button class="primary" type="button" (click)="filterResults(filter.value)">Search</button>
</form>
</section>
<section class="results">
@for(housingLocation of housingLocationList; track $index) {
@for (housingLocation of filteredLocationList; track $index) {
<app-housing-location [housingLocation]="housingLocation"></app-housing-location>
}
</section>

View File

@@ -15,7 +15,18 @@ import {HousingService} from '../housing'; // Importation d'un service
export class Home {
housingLocationList: HousingLocationInfo[] = [];
housingService: HousingService = inject(HousingService);
filteredLocationList: HousingLocationInfo[] = [];
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()),);
}
}