import { Component , OnInit , AfterViewInit } from '@angular/core' ; import { SearchService } from '../../services/search.service' ; @ Component ( { selector : 'dg-search' , templateUrl : './search.component.html' } ) export class SearchComponent implements OnInit , AfterViewInit { public searchText : string ; public isFocus : boolean ; public hasSearchText : boolean ; constructor ( public searchService ) { } ngOnInit ( ) { } ngAfterViewInit ( ) { this . searchService . initSearch ( '#inputSearch' ) ; } focus ( ) { this . isFocus = true ; } blur ( ) { setTimeout ( ( ) => { this . isFocus = false ; this . searchText = '' ; this . hasSearchText = false ; } , 200 ) ; } change ( ) { setTimeout ( ( ) => { this . hasSearchText = ! ! this . searchText ?. trim ( ) ; } , 200 ) ; } }