Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

139
Vistas
Reading routing parameter in HTML

We can set the routing parameter through HTML:

<a [routerLink] = "['/api/foo/', id]"/>

I know that we can read routing parameter through handling event in the typescript:

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

@Component({...})
export class MyComponent implements OnInit{

  constructor(private activatedRoute: ActivatedRoute) {}

  ngOnInit() {
    // subscribe to router event
    this.activatedRoute.params.subscribe((params: Params) => {
        let Id = params['id'];
        console.log(Id);
      });
  }
}

However, is there any way to read route parameter in the HTML, not in the TypeScript component?

I would like to use in the following manner:

<a href="api/foo/[routerLink]"/>
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

if you want to get id as number. You can use this.

id:number;

 ngOnInit() {

        this.subscription = this.activatedRoute.params.subscribe(
          (params: any) => {
            if (params.hasOwnProperty('id')) {
               id= +params['id'];
              //do whatever you want
            }
          }
        );

      }

and this destroyed the subscription

ngOnDestroy() {
    this.subscription.unsubscribe();
  }

and you can access the id field on html side.

over 4 years ago · Santiago Trujillo Denunciar

0

If you want to get the param in html it is better to assign the param to a variable and use it in html

private param:number;

private ngOnInit() {
    // subscribe to router event
    this.activatedRoute.params.subscribe((params: Params) => {
        this.param = params['id'];
        console.log(this.param);
      });
  }

in your html

<div>{{param}}</div>
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda