Skip to content

Instantly share code, notes, and snippets.

@Armenvardanyan95
Created July 2, 2017 12:14
Show Gist options
  • Save Armenvardanyan95/50fdcc7b58b825aef96a2764e26f29be to your computer and use it in GitHub Desktop.
Save Armenvardanyan95/50fdcc7b58b825aef96a2764e26f29be to your computer and use it in GitHub Desktop.
@Pipe({
name: 'slashed'
})
export class Slashed implements PipeTransform {
transform(value){
return value.map(item => {
return {
label: '/' + item.label,
value: item.value
};
})
}
}
@Component({
selector: 'some-component',
template: `
<div>
<dropdown-component [options]="weightUnits"></dropdown-component>
<input type="text" placeholder="Price">
<dropdown-component [options]="(weightUnits | slashed)"></dropdown-component>
<-- This will do the job -->
</div>
`
})
export class SomeComponent {
public weightUnits = [{value: 1, label: 'kg'}, {value: 2, label: 'oz'}];
// we will delegate the data transformation to a pipe
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment