1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

How Can I Get the Value of a Route Parameter?

Discussão em 'Angular' iniciado por Duplosion, Outubro 25, 2024 às 19:12.

  1. Duplosion

    Duplosion Guest

    I'm working in Angular 18.

    In my app.routes.ts file, I have the below:

    import { Routes } from '@angular/router';
    import { ShowComponent } from './components/show/show.component';

    export const routes: Routes = [
    { path: 'setlist/:showdate', component: ShowComponent }
    ];


    Then in my show.component.ts, I have:

    import { ActivatedRoute } from '@angular/router';

    export class ShowComponent implements OnInit {

    constructor(private route: ActivatedRoute) {}

    ngOnInit() {

    const showdate = String(this.route.snapshot.paramMap.get('showdate'));
    console.log(showdate);
    }}


    Then, let's say I visit /setlist/123

    showdate is null

    What am I missing here?

    Thanks!

    Continue reading...

Compartilhe esta Página