Created
March 29, 2017 17:52
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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