diff --git a/src/app/shared/navbar/navbar.component.html b/src/app/shared/navbar/navbar.component.html index 38cfc6c..979211f 100644 --- a/src/app/shared/navbar/navbar.component.html +++ b/src/app/shared/navbar/navbar.component.html @@ -3,7 +3,7 @@
+ ngModel [(ngModel)]="keyword" [value]="keyword" (keypress)="search($event)"> diff --git a/src/app/shared/navbar/navbar.component.ts b/src/app/shared/navbar/navbar.component.ts index 93e7de0..177fe27 100644 --- a/src/app/shared/navbar/navbar.component.ts +++ b/src/app/shared/navbar/navbar.component.ts @@ -1,21 +1,23 @@ import { Component, OnInit } from '@angular/core'; +import { Router } from '@angular/router'; import slugify from 'slugify'; import { API_SUB } from 'src/app/_api/apiURL'; import { FeedModel } from 'src/app/_model/feed.model'; import { TokenStorageService } from "../../_service/token-storage.service"; declare var $: any; - @Component({ selector: 'app-navbar', templateUrl: './navbar.component.html', styleUrls: ['./navbar.component.scss'] }) + export class NavbarComponent implements OnInit { currentUser: any; keyword!: string; feeds_list!: FeedModel[]; - constructor(private tokenStorage: TokenStorageService) { + + constructor(private tokenStorage: TokenStorageService, private router: Router) { } ngOnInit(): void { @@ -30,6 +32,14 @@ export class NavbarComponent implements OnInit { }); } + search(event: KeyboardEvent) { + if (event.code === "Enter") { + const url = $(".button__search").attr("href"); + this.closeSearchBox(); + this.router.navigateByUrl(url); + } + } + openSearchBox() { $("#search__overlay").fadeIn(500); $("input[name='keyword']").val(""); diff --git a/src/app/shared/search/search.component.html b/src/app/shared/search/search.component.html index 0d8c273..ea7df00 100644 --- a/src/app/shared/search/search.component.html +++ b/src/app/shared/search/search.component.html @@ -1,7 +1,7 @@
- + + class="btn text-primary bg-danger ml-20 search__action">
diff --git a/src/app/shared/search/search.component.ts b/src/app/shared/search/search.component.ts index a7747b7..b126122 100644 --- a/src/app/shared/search/search.component.ts +++ b/src/app/shared/search/search.component.ts @@ -29,6 +29,13 @@ export class SearchComponent implements OnInit { this.updateOption(); } + search(event: KeyboardEvent) { + if (event.code === "Enter") { + const url = $(".search__action").attr("href"); + this.router.navigateByUrl(url); + } + } + load_data() { this.activatedRoute.params.subscribe((params) => { this.keyword = params['keyword'];