avancement searchBar

This commit is contained in:
Romain Verger 2022-02-18 17:22:53 +01:00
parent 3dcdbfb405
commit e8a1dcc759
3 changed files with 15 additions and 24 deletions

View file

@ -1,5 +1,5 @@
import { Component, EventEmitter, OnInit, Output } from '@angular/core'; import { Component, EventEmitter, OnInit, Output } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router'; import { Router } from '@angular/router';
import { ApiBackService } from 'src/app/services/api-back.service'; import { ApiBackService } from 'src/app/services/api-back.service';
@Component({ @Component({
@ -9,37 +9,33 @@ import { ApiBackService } from 'src/app/services/api-back.service';
}) })
export class SearchBarComponent implements OnInit { export class SearchBarComponent implements OnInit {
searchText = new EventEmitter(); searchText = new EventEmitter();
listRestau: any []; listRestau: any[];
restauByName : any[]; restauByName: any[];
constructor(private apiBackService : ApiBackService, private route: Router, private activatedRoute: ActivatedRoute) { constructor(private apiBackService: ApiBackService, private route: Router) {
this.listRestau = []; this.listRestau = [];
this.restauByName = []; this.restauByName = [];
} }
ngOnInit(): void { ngOnInit(): void {
this.apiBackService.getRestaurants().subscribe((restaurants: any[]) => { this.apiBackService.getRestaurants().subscribe((restaurants: any[]) => {
this.listRestau = restaurants; this.listRestau = restaurants;
}); });
console.log(this.listRestau);
} }
onChangeInput(search :string) { onChangeInput(search: string) {
this.restauByName = this.listRestau;
// this.searchText.emit(search) this.restauByName = this.restauByName.filter((restau: any) =>
this.restauByName = this.listRestau; restau.nom.toLowerCase().includes(search.toLowerCase()));
this.restauByName = this.restauByName.filter((restau : any) => console.log(this.restauByName);
restau.nom.toLowerCase().includes(search.toLowerCase()));
console.log(this.restauByName);
this.apiBackService.setListRestau(this.restauByName, "filtres");
this.route.navigate(['restaurants']);
this.apiBackService.setListRestau(this.restauByName, "filtres");
this.route.navigate(['restaurants']);
}
} }
}

View file

@ -129,9 +129,6 @@ export class FiltersPageComponent implements OnInit {
// ------------------------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------------------------
console.log(this.activatedRoute.snapshot.routeConfig?.path);
console.log(restaus);
this.apiBackService.setListRestau(restaus, this.activatedRoute.snapshot.routeConfig?.path); this.apiBackService.setListRestau(restaus, this.activatedRoute.snapshot.routeConfig?.path);
// on fait passer en second parametre le path de la route c'est a dire "filtres" // on fait passer en second parametre le path de la route c'est a dire "filtres"
this.route.navigate(['restaurants']); this.route.navigate(['restaurants']);