aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/header/suggestions.component.ts
blob: fac7fe2f97b00fe5b80b37e510bef938a3ee4f75 (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
25
26
27
28
29
30
import { Input, QueryList, Component, Output, AfterViewInit, EventEmitter, ViewChildren } from '@angular/core'
import { SuggestionComponent } from './suggestion.component'

@Component({
  selector: 'my-suggestions',
  template: `
    <ul role="listbox" class="p-0 m-0">
      <li *ngFor="let result of results; let i = index" class="d-flex flex-justify-start flex-items-center p-0 f5"
          role="option" aria-selected="true" (mouseenter)="hoverItem(i)">
        <my-suggestion [result]="result" [highlight]="highlight"></my-suggestion>
      </li>
    </ul>
  `
})
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(
      val => this.init.emit({ items: this.listItems })
    )
  }

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