Skip to content

Commit

Permalink
Merge pull request #68 from Kichrum/feat/search-by-code
Browse files Browse the repository at this point in the history
Enable searching by the dial code
  • Loading branch information
tanansatpal authored Sep 9, 2020
2 parents cf47b08 + 75bc24d commit 1b6c5bb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</button>
<mat-divider *ngIf="preferredCountriesInDropDown?.length"></mat-divider>
<ng-container *ngFor="let country of allCountries">
<button type="button" mat-menu-item class="country-list-button" *ngIf="country.name | search:searchCriteria" (click)="onCountrySelect(country, focusable)">
<button type="button" mat-menu-item class="country-list-button" *ngIf="country | search:searchCriteria" (click)="onCountrySelect(country, focusable)">
<div class="icon-wrapper">
<div class="flag" [ngClass]="country.flagClass"></div>
</div>
Expand Down
10 changes: 8 additions & 2 deletions projects/ngx-mat-intl-tel-input/src/lib/search.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import { Pipe, PipeTransform } from '@angular/core';

import { Country } from './model/country.model';

@Pipe({
name: 'search'
})
export class SearchPipe implements PipeTransform {

// country | search:'searchCriteria'
transform(country: any, searchCriteria?: any): any {
transform(country: Country, searchCriteria?: string): boolean {
if (!searchCriteria || searchCriteria === '') {
return true;
}

return country.toLowerCase().includes(searchCriteria.toLowerCase());
return `${country.name}+${country.dialCode}`
.toLowerCase()
.includes(
searchCriteria.toLowerCase()
);
}

}

0 comments on commit 1b6c5bb

Please sign in to comment.