Skip to content

Commit

Permalink
Rutas con parametros
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJonaCode committed Sep 25, 2020
1 parent a68a3a8 commit 159a940
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ import { NavbarComponent } from './components/shared/navbar/navbar.component';
import { HomeComponent } from './components/home/home.component';
import { AboutComponent } from './components/about/about.component';
import { HeroesComponent } from './components/heroes/heroes.component';
import { HeroeComponent } from './components/heroe/heroe.component';

@NgModule({
declarations: [
AppComponent,
NavbarComponent,
HomeComponent,
AboutComponent,
HeroesComponent
HeroesComponent,
HeroeComponent
],
imports: [
BrowserModule,
Expand Down
2 changes: 2 additions & 0 deletions src/app/app.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { RouterModule, Routes } from '@angular/router';
import { HomeComponent } from './components/home/home.component';
import { HeroesComponent } from './components/heroes/heroes.component';
import { AboutComponent } from './components/about/about.component';
import { HeroeComponent } from './components/heroe/heroe.component';

const APP_ROUTES: Routes = [
{ path: 'home', component: HomeComponent },
{ path: 'about', component: AboutComponent },
{ path: 'heroes', component: HeroesComponent },
{ path: 'heroe/:id', component: HeroeComponent},
{ path: '**', pathMatch: 'full', redirectTo: 'home' }
];

Expand Down
1 change: 1 addition & 0 deletions src/app/components/heroe/heroe.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>heroe works!</p>
14 changes: 14 additions & 0 deletions src/app/components/heroe/heroe.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Component, OnInit } from '@angular/core';

@Component({
selector: 'app-heroe',
templateUrl: './heroe.component.html'
})
export class HeroeComponent implements OnInit {

constructor() { }

ngOnInit(): void {
}

}
6 changes: 4 additions & 2 deletions src/app/components/heroes/heroes.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ <h1>Heroes <small>Marvel y DC</small></h1>

<div class="card-columns">

<div class="card" *ngFor="let heroe of heroes">
<div class="card animated fadeIn fast" *ngFor="let heroe of heroes; let i = index">
<img [src]="heroe.img" class="card-img-top" [alt]="heroe.nombre">
<div class="card-body">
<h5 class="card-title">{{ heroe.nombre }}</h5>
<p class="card-text">{{ heroe.bio }}</p>
<p class="card-text"><small class="text-muted"> {{ heroe.aparicion }} </small></p>

<button type="button" class="btn btn-outline-primary btn-block">
<button (click) = "verHeroe(i)"
type="button" class="btn btn-outline-primary btn-block">
Ver más...
</button>
<!-- <a [routerLink]="['/heroe',i]" class="btn btn-outline-primary">Ver más Link... </a> -->

</div>
</div>
Expand Down
14 changes: 10 additions & 4 deletions src/app/components/heroes/heroes.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { HeroesService, Heroe } from '../../servicios/heroes.service';
import { Router } from '@angular/router';


@Component({
Expand All @@ -12,16 +13,21 @@ export class HeroesComponent implements OnInit {

heroes: Heroe[] = [];

constructor( private _heroesService:HeroesService ) {
console.log('Constructor');
constructor( private _heroesService:HeroesService,
private router:Router
) {
//console.log('Constructor');
}

ngOnInit(): void {

this.heroes = this._heroesService.getHeroes();

console.log(this.heroes);
//console.log(this.heroes);
}

verHeroe( idx:number ){
this.router.navigate( ['/heroe', idx] );
}

}

0 comments on commit 159a940

Please sign in to comment.