import {Component, ElementRef, OnInit, ViewChild} from '@angular/core'; import {ActivatedRoute} from '@angular/router'; import {Result} from '../../interfaces/result.interface'; import {MOCK_RESULT} from '../../mock/mock-data'; @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) { } ngOnInit() { this.route.queryParams.subscribe(params => { this.queryString = params.q; }); // Mock results setTimeout(() => { this.results = MOCK_RESULT; this.resultDiv.nativeElement.scrollIntoView({behavior: 'smooth', block: 'start'}); }, 1000); } }