aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/header/suggestions.component.ts
blob: ee3ef73c2c8f617e37c662b2a41f7b053571ff29 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { Input, QueryList, Component, Output, AfterViewInit, EventEmitter, ViewChildren, ChangeDetectionStrategy } from '@angular/core'
import { SuggestionComponent } from './suggestion.component'

@Component({
  selector: 'my-suggestions',
  templateUrl: './suggestions.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class SuggestionsComponent implements AfterViewInit {
  @Input() results: any[]
  @Input() highlight: string
  @ViewChildren(SuggestionComponent) listItems: QueryList<SuggestionComponent>
  @Output() init = new EventEmitter()

  ngAfterViewInit () {
    this.listItems.changes.subscribe(
      _ => this.init.emit({ items: this.listItems })
    )
  }

  hoverItem (index: number) {
    this.init.emit({ items: this.listItems, index: index })
  }
}