Skip to content

Instantly share code, notes, and snippets.

@amirping
Created February 14, 2018 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amirping/f1d5d697a5962f5d9948b5cd65dcdfd6 to your computer and use it in GitHub Desktop.
Save amirping/f1d5d697a5962f5d9948b5cd65dcdfd6 to your computer and use it in GitHub Desktop.
pip help
import { Pipe, PipeTransform } from '@angular/core';
import { radio } from '../classes/radio';
@Pipe({ name: 'searchRadio' })
export class SearchRadioPipe implements PipeTransform {
transform(allRadios: radio[] , name :string , location:string) {
let result ;
let final ;
let respat = RegExp(".","g"); // match any thing
if(name.length != 0){
respat = RegExp("^.*"+name+".*$","gi");
result = allRadios.filter(radio => radio.name.search(respat)!=-1);
}
else{
result = allRadios;
}
// location search from result and not from arg
if(location.length != 0){
let locreg = RegExp("^.*"+location+".*$","gi");
final = result.filter(radio => radio.location.search(locreg)!=-1);
}
else{
final = result ;
}
return final;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment