Skip to content

Instantly share code, notes, and snippets.

@gchokeen
Created March 29, 2017 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gchokeen/13f9885e1657fcb36d1322d6934da4f7 to your computer and use it in GitHub Desktop.
Save gchokeen/13f9885e1657fcb36d1322d6934da4f7 to your computer and use it in GitHub Desktop.
Angular 2 custom pipe for full address - Address is extracted from the Address Object
import {Pipe, PipeTransform} from '@angular/core';
interface Address{
street_address1?:string,
street_address2?:string,
city?:string,
state?:string,
country?:string,
zipcode?:string
};
@Pipe({
name: 'fullAddress'
})
export class FullAddressPipe implements PipeTransform {
address:any;
transform(value: Address[], args: string[]): any {
this.address = ['street_address1','street_address2','city','state','country','zipcode'];
return Object.keys(value).map(key => {
if(this.address.indexOf(key) != -1){
return value[key] ==""?'':value[key];
}
return;
}).filter(key =>{
return key
}).join(', ');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment