Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

107
Visualizações
Problems displaying information from routing with Angular

My problem is this: I am making a movie application and the idea is that, when I click on the details button, the information about the movie I have pressed is displayed but I do not know how to do it. I have been able to send to the url as if it were a GET request the id of the movie but that's where I have the problem: how do I show the information from that id number without showing all the movies? I attach work for now.

import { Component, OnInit, Input } from '@angular/core';

@Component({
  selector: 'app-character',
  templateUrl: './character.component.html',
  styleUrls: ['./character.component.css']
})
export class CharacterComponent implements OnInit {
  @Input() character: any;

  constructor() { }

  ngOnInit() {
  }

  /**
   * FUNCION QUE CAMBIA EL NOMBRE DE THOR
   * POR OTRO BIEN PUESTO
   * @param titulo string que recibe el titulo de la película
   * @returns título bien puesto
   */
  formatName(titulo: string) {
    if (titulo == 'Thor: Ragnarok') {
      return 'THOR (RAGNAROK)';
    } else {
      return titulo;
    }
  }

  /**
   * FUNCION QUE DEVUELVE LA FASE DE LA PELÍCULA
   * @param titulo titulo de la película
   * @returns la fase que le pertenece
   */
  muestroFase(titulo: string) {
    if (titulo == 'Iron Man' || titulo == 'Captain America' || titulo == 'The Avengers') {
      return "Fase 1";
    } else if (titulo == 'Ant-man') {
      return "Fase 2";
    } else {
      return "Fase 3";
    }
  }

}

The charcater.ts that contacts the.component services API to display the information.

<mat-card>
  <img mat-card-image src="{{character.poster}}" alt="{{character.name}}">
  <mat-card-title>
    {{character.id}}.- {{formatName(character.name)}} {{muestroFase(character.name)}}
  </mat-card-title>
  <mat-card-footer>
    <a routerLink="/info/{{character.id}}" fxFlex mat-flat-button color="primary">
      Detalles
    </a>
  </mat-card-footer>
</mat-card>

The html of this component that displays the movies.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I replicated your code on stackblitz (with simple html instead of material), imported RouterModule in app.module and looks fine.

https://stackblitz.com/edit/angular-ivy-7aauwd?file=src/app/character/character.component.html

routerLink is pointing correctly to /info/:id

Nothing happen after clicking because... no routes were defined.

I'm not really sure what your asking. If you already created a component to show the movies list, you need a second component in the router that catches the /info/:id in the path.

https://angular.io/guide/router-tutorial-toh

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda