Skip to content

Instantly share code, notes, and snippets.

@jhades
Last active May 12, 2016 07:39
Show Gist options
  • Save jhades/f0a061081993be7d5b21a86ac894bd88 to your computer and use it in GitHub Desktop.
Save jhades/f0a061081993be7d5b21a86ac894bd88 to your computer and use it in GitHub Desktop.
Components Essentials
@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');
}
}
@Component({
selector: 'color-previewer',
template: `
<div class="color-previewer" [ngStyle]="{color:color}">
Preview Text Color
</div>
`
})
export class ColorPreviewer {
@Input()
color:string;
}
@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