Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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