Angular 16 Get Routing Parameters with @Input

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.
- Author: Ahmed Bouchefra Follow @ahmedbouchefra
-
Date:
Related posts
Angular 16 Signals - mutate & update examples Node.js v20.6.0: Introducing Built-in .env File Support Angular 16 Get Routing Parameters with @Input Angular 16 Required Input with Example Angular 16 provideRouter Example: Use Standalone Components with Angular 16 Router Add Jest Support to Angular 16 Angular 16 Inject HttpClient Angular 16 Get the Current Route Example Converting Signals to Observables in Angular 16 Angular 16 Signals ExplainedHands-on Angular eBook
Subscribe to our Angular newsletter and get our hands-on Angular book for free!
