ng-semantic
Version:
Angular2 building blocks based on Semantic UI
37 lines (34 loc) • 1.35 kB
text/typescript
import { Component, ChangeDetectionStrategy, Input, Output, EventEmitter, AfterViewInit } from "@angular/core";
import { FormControl } from "@angular/forms";
import "rxjs/add/operator/debounceTime";
import "rxjs/add/operator/distinctUntilChanged";
/**
* <sm-search placeholder="Search..." (onSearch)="element.innerText = $event" ></sm-search>
*/
export class SemanticSearchComponent implements AfterViewInit {
class: string;
icon: boolean;
loading: boolean;
debounce: number = 0;
placeholder: string;
onSearch: EventEmitter<string|number> = new EventEmitter<string|number>();
searchControl: FormControl = new FormControl();
ngAfterViewInit() {
this.searchControl
.valueChanges
.distinctUntilChanged()
.debounceTime(this.debounce)
.subscribe((data: string|number) => this.onSearch.emit(data));
}
}