Skip to content

Commit

Permalink
Buscador de heroes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJonaCode committed Sep 25, 2020
1 parent d418c8a commit fa8ff0a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/app/components/shared/navbar/navbar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-primary my-2 my-sm-0" type="submit">Search</button>
<input class="form-control mr-sm-2" type="search" placeholder="Buscar heroe" aria-label="Search" (keyup.enter)="buscarHeroe(buscarTexto.value)" #buscarTexto>
<button (click)="buscarHeroe(buscarTexto.value)"
class="btn btn-outline-primary my-2 my-sm-0" type="button">Buscar</button>
</form>
</div>
</nav>
4 changes: 4 additions & 0 deletions src/app/components/shared/navbar/navbar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ export class NavbarComponent implements OnInit {
ngOnInit(): void {
}

buscarHeroe( termino:string){
console.log(termino);
}

}
14 changes: 14 additions & 0 deletions src/app/servicios/heroes.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ export class HeroesService{
return this.heroes[idx];
}


buscarHeroes( termino:string){

let heroesArr:Heroe[] = [];
termino = termino.toLowerCase();

for( let heroe of this.heroes ){
let nombre = heroe.nombre.toLowerCase();
if (nombre.indexOf( termino ) >=0){
heroesArr.push( heroe )
}
}
return heroesArr;
}
}

export interface Heroe{
Expand Down

0 comments on commit fa8ff0a

Please sign in to comment.