nav-bar.component.ts
1.08 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { Component, OnInit } from '@angular/core';
import { Observable, interval } from 'rxjs';
import { switchMap, take, switchMapTo } from 'rxjs/operators';
import { filter } from 'rxjs/operators';
import { Router, ActivatedRoute, NavigationStart, Navigation } from '@angular/router';
@Component({
selector: 'nav-bar',
templateUrl: './nav-bar.component.html',
styleUrls: ['./nav-bar.component.css']
})
export class NavBarComponent implements OnInit {
search : string = '';
suggestion : boolean = false;
private clearSearch$;
constructor(
private route: ActivatedRoute,
private router: Router,
) { }
ngOnInit(): void {
/* On route change, clear search bar */
this.clearSearch$ = this.router.events.pipe(
filter(event => event instanceof NavigationStart)
)
.subscribe( (event : NavigationStart) => {
this.search = '';
this.suggestion = false;
} );
}
showinput() {
/** this needs to be done with switchmap **/
if (this.search == "") {
this.hideinput()
}
else {
this.suggestion = true;
}
}
hideinput() {
this.suggestion = false;
}
}