step 13
This commit is contained in:
@@ -30,11 +30,11 @@ import {FormControl, FormGroup, ReactiveFormsModule} from '@angular/forms';
|
|||||||
<h2 class="section-heading">Apply now to live here</h2>
|
<h2 class="section-heading">Apply now to live here</h2>
|
||||||
<form [formGroup]="applyForm" (submit)="submitApplication()">
|
<form [formGroup]="applyForm" (submit)="submitApplication()">
|
||||||
<label for="first-name">First Name</label>
|
<label for="first-name">First Name</label>
|
||||||
<input id="first-name" type="text" formControlName="firstName" />
|
<input id="first-name" type="text" formControlName="firstName"/>
|
||||||
<label for="last-name">Last Name</label>
|
<label for="last-name">Last Name</label>
|
||||||
<input id="last-name" type="text" formControlName="lastName" />
|
<input id="last-name" type="text" formControlName="lastName"/>
|
||||||
<label for="email">Email</label>
|
<label for="email">Email</label>
|
||||||
<input id="email" type="email" formControlName="email" />
|
<input id="email" type="email" formControlName="email"/>
|
||||||
<button type="submit" class="primary">Apply now</button>
|
<button type="submit" class="primary">Apply now</button>
|
||||||
</form>
|
</form>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
<section>
|
<section>
|
||||||
<form>
|
<form><input type="text" placeholder="Filter by city" #filter/>
|
||||||
<input type="text" placeholder="Filter by city" />
|
<button class="primary" type="button" (click)="filterResults(filter.value)">Search</button>
|
||||||
<button class="primary" type="button">Search</button>
|
|
||||||
</form>
|
</form>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="results">
|
<section class="results">
|
||||||
@for(housingLocation of housingLocationList; track $index) {
|
@for (housingLocation of filteredLocationList; track $index) {
|
||||||
<app-housing-location [housingLocation]="housingLocation"></app-housing-location>
|
<app-housing-location [housingLocation]="housingLocation"></app-housing-location>
|
||||||
}
|
}
|
||||||
</section>
|
</section>
|
||||||
@@ -15,7 +15,18 @@ import {HousingService} from '../housing'; // Importation d'un service
|
|||||||
export class Home {
|
export class Home {
|
||||||
housingLocationList: HousingLocationInfo[] = [];
|
housingLocationList: HousingLocationInfo[] = [];
|
||||||
housingService: HousingService = inject(HousingService);
|
housingService: HousingService = inject(HousingService);
|
||||||
|
filteredLocationList: HousingLocationInfo[] = [];
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.housingLocationList = this.housingService.getAllHousingLocations();
|
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()),);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user