Created
July 2, 2017 12:14
-
-
Save Armenvardanyan95/50fdcc7b58b825aef96a2764e26f29be to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| @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