Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

106
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!