Created
April 30, 2018 20:44
-
-
Save sulco/f1e69d0e453bd9c753639454af2bc099 to your computer and use it in GitHub Desktop.
Simple one-file Angular component with `ViewEncapsulation.Native`
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 { Input, Component, ViewEncapsulation, EventEmitter, Output } from '@angular/core'; | |
@Component({ | |
selector: 'custom-button', | |
template: `<button (click)="handleClick()">{{label}}</button>`, | |
styles: [` | |
button { | |
border: solid 3px; | |
padding: 8px 10px; | |
background: #bada55; | |
font-size: 20px; | |
} | |
`], | |
encapsulation: ViewEncapsulation.Native | |
}) | |
export class ButtonComponent { | |
@Input() label = 'default label'; | |
@Output() action = new EventEmitter<number>(); | |
private clicksCt = 0; | |
handleClick() { | |
this.clicksCt++; | |
this.action.emit(this.clicksCt); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
don't we have to do something like this?
constructor() { super();}