Loading episodes…
0:00 0:00

Angular 16 Get Routing Parameters with @Input

00:00
BACK TO HOME

Angular 16 Get Routing Parameters with @Input

10xTeam September 07, 2023 1 min read

With the introduction of Angular 16, developers now have a more straightforward method for accessing information about the current route. This new feature allows you to retrieve the current routing parameters via the @Input, decreasing the amount of boilerplate code necessary dramatically.

Previously, to access information about the current route, you have to inject ActivatedRoute into the component and utilize the snapshot property to extract the route parameters.

Now this is simply done as follows.

The new method greatly simplifies the procedure. All you have to do now is declare an input property with the parameter name, as seen below.

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

@Component({
  selector: 'app-profile',
  templateUrl: './profile.component.html',
  styleUrls: ['./profile.component.css'],
})
export class ProfileComponent {
  @Input() id!: string;
}

This new feature allows you to retrieve the current routing parameter via the @input property, which provides an alternate and more simplified method of obtaining the information.


Join the 10xdev Community

Subscribe and get 8+ free PDFs that contain detailed roadmaps with recommended learning periods for each programming language or field, along with links to free resources such as books, YouTube tutorials, and courses with certificates.

Audio Interrupted

We lost the audio stream. Retry with shorter sentences?