import { Component, Output, EventEmitter, ElementRef, ViewChild, OnInit }
from '@angular/core';
import { fromEvent } from 'rxjs';
import { debounceTime, map, distinctUntilChanged, filter } from
rxjs/operators'
@Component({
selector: 'app-child',
template: `
<input #inputSearch placeholder="Write something"/>`
})
export class HijoComponent implements OnInit {
@Output() inputText: EventEmitter<any> = new EventEmitter();
@ViewChild('inputSearch') inputSearch: ElementRef
constructor(){
}
ngOnInit(){
fromEvent(this.inputSearch.nativeElement, 'keyup').
pipe(
map((evt: any) => evt.target.value),
filter(res => res.length > 2),
debounceTime(1000),
distinctUntilChanged()
).subscribe((c : string)=> {
this.inputText.emit(c)
});
}
}