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

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

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 Report

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 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!