Last active
May 12, 2016 07:39
-
-
Save jhades/f0a061081993be7d5b21a86ac894bd88 to your computer and use it in GitHub Desktop.
Components Essentials
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
@Component({ | |
selector: 'color-picker', | |
template: ` | |
<div class="color-title" [ngStyle]="{color:color}">Pick a Color:</div> | |
<div class="color-picker"> | |
<div class="color-sample color-sample-blue" (click)="choose('${BLUE}')"></div> | |
<div class="color-sample color-sample-red" (click)="choose('${RED}')"></div> | |
</div> | |
` | |
}) | |
export class ColorPicker { | |
@Input() | |
color:string; | |
@Output("color") | |
colorOutput = new EventEmitter(); | |
choose(color) { | |
this.colorOutput.emit(color); | |
} | |
reset() { | |
this.colorOutput.emit('black'); | |
} | |
} |
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
@Component({ | |
selector: 'color-previewer', | |
template: ` | |
<div class="color-previewer" [ngStyle]="{color:color}"> | |
Preview Text Color | |
</div> | |
` | |
}) | |
export class ColorPreviewer { | |
@Input() | |
color:string; | |
} |
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
@Component({ | |
selector: 'app', | |
directives: [ColorPreviewer, ColorPicker], | |
template: ` | |
<color-picker #picker [color]="color" (color)="color = $event"> | |
</color-picker> | |
<color-previewer #previewer [color]="color"></color-previewer> | |
<button (click)="picker.reset()">Reset</button> | |
` | |
}) | |
export class App { | |
color:string; | |
} | |
bootstrap(App); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment