travopti/frontend/src/app/containers/search/search.component.ts
2020-06-18 00:52:27 +02:00

31 lines
913 B
TypeScript

import {Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {Result} from '../../interfaces/result.interface';
import {DataService} from '../../services/data.service';
@Component({
selector: 'app-search',
templateUrl: './search.component.html',
styleUrls: ['./search.component.scss']
})
export class SearchComponent implements OnInit {
queryString: string;
results: Result[];
@ViewChild('result', {static: false})
resultDiv: ElementRef;
constructor(private route: ActivatedRoute, private ds: DataService) {
}
async ngOnInit() {
this.route.queryParams.subscribe(async params => {
this.queryString = params.q;
this.results = undefined;
this.results = await this.ds.searchRegions(this.queryString);
this.resultDiv.nativeElement.scrollIntoView({behavior: 'smooth', block: 'start'});
});
}
}