Last active
March 16, 2017 13:06
-
-
Save kenmlee/865fad590b4f6e89318d745b45bd8890 to your computer and use it in GitHub Desktop.
components with input and output
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
.btn-clear { | |
background: #DE363F; | |
color: white; | |
font-weight: bold; | |
border-radius: 4px; | |
} |
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
<input placeholder="{{text}}" #box | |
(keydown.enter)="onSearch(box.value)"> | |
<button class="btn-clear" (click)="clear(box)">Clear</button> |
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
import {Component, Input, EventEmitter, Output} from "@angular/core"; | |
declare const module; | |
@Component({ | |
selector: 'search-box', | |
moduleId: module.id, | |
templateUrl: 'search-box.component.html', | |
styleUrls: ['search-box.component.css'] | |
}) | |
export class SearchBox { | |
@Input() | |
text:string; | |
@Output() | |
search = new EventEmitter(); | |
clear(box) { | |
box.value = ''; | |
} | |
onSearch(searchText) { | |
this.search.emit(searchText); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment