From 3dcdbfb405a6a9a3c2ba636d8ee1bd796f6ec3d1 Mon Sep 17 00:00:00 2001 From: Romain Verger Date: Fri, 18 Feb 2022 16:41:52 +0100 Subject: [PATCH] ajout Fonction searchBar --- src/app/app.component.html | 2 +- src/app/app.component.ts | 26 +------------- .../search-bar/search-bar.component.ts | 35 ++++++++++++++++--- 3 files changed, 32 insertions(+), 31 deletions(-) diff --git a/src/app/app.component.html b/src/app/app.component.html index 8f1b7f7..cc2f543 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -1,4 +1,4 @@ - + diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 7d379f0..7d60f78 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -10,9 +10,6 @@ import { ApiBackService } from './services/api-back.service'; export class AppComponent { title = 'simpleat'; dontShow: boolean = false; - searchParam: any; - listResto: any; - constructor(private router:Router, private apiBackService : ApiBackService){ this.router.events.subscribe(e=>{ @@ -27,29 +24,8 @@ export class AppComponent { } }) - - - this.searchParam = { - searchText : "", - filterText : "first" - } - } - ngOnInit(): void { - - this.listResto = this.apiBackService.getRestaurants(); - - console.log(this.listResto) - } - - // onSearchResto(searchText: string,) { - // this.searchParam.searchText = searchText; - // const rawData = this.apiBackService.getRestaurants(); - - // this.listResto = rawData.filter(resto => - // resto.name.toLowerCase().includes(searchText.toLowerCase())) - // } - + ngOnInit(): void { } } diff --git a/src/app/header/components/search-bar/search-bar.component.ts b/src/app/header/components/search-bar/search-bar.component.ts index 0ada60f..99d046c 100644 --- a/src/app/header/components/search-bar/search-bar.component.ts +++ b/src/app/header/components/search-bar/search-bar.component.ts @@ -1,4 +1,6 @@ import { Component, EventEmitter, OnInit, Output } from '@angular/core'; +import { ActivatedRoute, Router } from '@angular/router'; +import { ApiBackService } from 'src/app/services/api-back.service'; @Component({ selector: 'app-search-bar', @@ -7,14 +9,37 @@ import { Component, EventEmitter, OnInit, Output } from '@angular/core'; }) export class SearchBarComponent implements OnInit { -@Output() searchText = new EventEmitter(); +searchText = new EventEmitter(); +listRestau: any []; +restauByName : any[]; - constructor() {} + constructor(private apiBackService : ApiBackService, private route: Router, private activatedRoute: ActivatedRoute) { - ngOnInit(): void {} + this.listRestau = []; + this.restauByName = []; + } + + ngOnInit(): void { + + this.apiBackService.getRestaurants().subscribe((restaurants: any[]) => { + this.listRestau = restaurants; + }); + console.log(this.listRestau); + + } onChangeInput(search :string) { - this.searchText.emit(search); - console.log(search); + + + // this.searchText.emit(search) + this.restauByName = this.listRestau; + this.restauByName = this.restauByName.filter((restau : any) => + restau.nom.toLowerCase().includes(search.toLowerCase())); + + console.log(this.restauByName); + + this.apiBackService.setListRestau(this.restauByName, "filtres"); + this.route.navigate(['restaurants']); + } }