feat: started details page
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { CommonModule } from "@angular/common";
|
||||
import { Component, ElementRef, EventEmitter, Output, ViewChild } from "@angular/core";
|
||||
import { AfterViewInit, Component, ElementRef, ViewChild } from "@angular/core";
|
||||
import { ActivatedRoute, Router } from "@angular/router";
|
||||
|
||||
@Component({
|
||||
selector: "app-header",
|
||||
@@ -8,10 +9,13 @@ import { Component, ElementRef, EventEmitter, Output, ViewChild } from "@angular
|
||||
standalone: true,
|
||||
imports: [CommonModule],
|
||||
})
|
||||
export class HeaderComponent {
|
||||
@Output() searchEvent: EventEmitter<string> = new EventEmitter();
|
||||
export class HeaderComponent implements AfterViewInit {
|
||||
@ViewChild("searchInput") searchInput: ElementRef<HTMLInputElement> | null = null;
|
||||
menuOpened = false;
|
||||
constructor(
|
||||
private router: Router,
|
||||
private route: ActivatedRoute,
|
||||
) {}
|
||||
changeMenu() {
|
||||
this.menuOpened = !this.menuOpened;
|
||||
}
|
||||
@@ -27,7 +31,16 @@ export class HeaderComponent {
|
||||
search() {
|
||||
if (this.searchInput) {
|
||||
const text = this.searchInput.nativeElement.value;
|
||||
this.searchEvent.emit(text);
|
||||
this.router.navigateByUrl(`/?search=${text}`);
|
||||
}
|
||||
}
|
||||
|
||||
ngAfterViewInit(): void {
|
||||
this.route.queryParams.subscribe((params) => {
|
||||
const search = params["search"];
|
||||
if (search && this.searchInput) {
|
||||
this.searchInput.nativeElement.value = search;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user