Skip to content

Instantly share code, notes, and snippets.

@kenmlee
Last active March 16, 2017 13:06
Show Gist options
  • Save kenmlee/865fad590b4f6e89318d745b45bd8890 to your computer and use it in GitHub Desktop.
Save kenmlee/865fad590b4f6e89318d745b45bd8890 to your computer and use it in GitHub Desktop.
components with input and output
.btn-clear {
background: #DE363F;
color: white;
font-weight: bold;
border-radius: 4px;
}
<input placeholder="{{text}}" #box
(keydown.enter)="onSearch(box.value)">
<button class="btn-clear" (click)="clear(box)">Clear</button>
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