I'm trying to create a boolean filter for my results, by users who have financial debt and those who haven't, but I got lost and just can't figure out how to do it.
Search Pipe(working with text search)
@Pipe({
name: 'search'
})
export class SearchPipe implements PipeTransform {
transform(tenants:Tenant[], searchTerm : string): Tenant[] {
if(!tenants || !searchTerm){
return tenants;
}
return tenants.filter(tenant =>
tenant.name.toLocaleLowerCase().indexOf(searchTerm.toLocaleLowerCase()) !== -1);
}
}
ngOnInit() {
this.userService.getAllTenants().subscribe((data:Tenant[])=>{
this.lstTenants = data.Tenants;
console.log("Tenants:", this.lstTenants)
})
}
<div class="small-container">
<h1>Tenants</h1>
<button class="add" [routerLink]="['/add']">Add New Tenant</button>
<input type="search" placeholder="Search Tenants" [(ngModel)]="searchTerm" [ngModelOptions]="{standalone: true}">
<form>
<div class="form-group">
<label>
<span>Show financial Debt Only</span>
<input class="form-control mb-2" type="checkbox" [(ngModel)]="hasFinanacialDebt" [ngModelOptions]="{standalone: true}" >
</label>
</div>
<div class="form-group">
<label>
<span>Show none financial Debt Only</span>
<input class="form-control mb-2" type="checkbox" [(ngModel)]="hasntFinanacialDebt" [ngModelOptions]="{standalone: true}" >
</label>
</div>
</form>
<tr *ngFor="let tenant of lstTenants | search : searchTerm">
<td>{{tenant.name}}</td>
<td>{{tenant.phoneNumber}}</td>
<td>{{tenant.address}}</td>
<td>{{tenant.financialDebt}}</td>
</tr>
Interface file
export class Tenant {
name:String;
phoneNumber:Number
address:String;
financialDebt:Boolean
}
