home.component.ts 919 Bytes
Newer Older
1
import { Component, OnInit } from '@angular/core';
Exbrayat Cédric's avatar
Exbrayat Cédric committed
2
3
import { FormControl, FormGroup } from '@angular/forms';
import { Router } from '@angular/router';
4
5
6
import { Observable } from 'rxjs';

import { SearchService } from '../search.service';
Exbrayat Cédric's avatar
Exbrayat Cédric committed
7
8
9
10
11
12

@Component({
  selector: 'rare-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.scss']
})
13
export class HomeComponent implements OnInit {
Exbrayat Cédric's avatar
Exbrayat Cédric committed
14
  searchForm: FormGroup;
15
  suggesterTypeahead: (text$: Observable<string>) => Observable<Array<string>>;
Exbrayat Cédric's avatar
Exbrayat Cédric committed
16

17
  constructor(private router: Router, private searchService: SearchService) {
Exbrayat Cédric's avatar
Exbrayat Cédric committed
18
19
20
21
22
    this.searchForm = new FormGroup({
      search: new FormControl()
    });
  }

23
24
25
26
  ngOnInit(): void {
    this.suggesterTypeahead = this.searchService.getSuggesterTypeahead();
  }

Exbrayat Cédric's avatar
Exbrayat Cédric committed
27
28
29
30
31
32
33
34
  search() {
    this.router.navigate(['/search'], {
      queryParams: {
        query: this.searchForm.get('search').value
      }
    });
  }
}