Back to notes
Which service would you inject to access the route parameters within a component?
Press to flip
ActivatedRoute
Name two essential steps to configure navigation in Angular.
1. Configure the route 2. Add a router outlet
What is the purpose of the `<router-outlet>` directive?
It acts as a placeholder where the routed component is displayed.
Explain how you can access route parameters in a component.
Using the `ActivatedRoute` service, e.g., `this.route.paramMap.subscribe(params => {...})`
How do you dynamically create links in Angular for navigation purposes?
Use the `routerLink` directive, e.g., `<a [routerLink]='['/posts']'>Posts</a>`
What is the purpose of the wildcard path in route definitions?
It is used to catch all unmatched routes, typically pointing to a Not Found component.
Provide an example of a component displayed for non-matching routes.
{ path: '**', component: NotFoundComponent }
When should `RouterModule.forChild(routes)` be used?
For defining routes within child modules
How would you define a route with query parameters in Angular?
Use a colon in the path for parameters, e.g., `{ path: 'profile/:username', component: GithubProfileComponent }`
What is the syntax to import the RouterModule in an Angular module?
import { RouterModule } from '@angular/router';
What directive would you use to apply CSS classes to an active link?
routerLinkActive
What Angular module is essential for implementing routing?
RouterModule
How do you define root-level routes for an Angular application?
Use `RouterModule.forRoot(routes)`
Explain the role of `routerLinkActive` in navigation.
It dynamically applies CSS classes to links when they are active.
What method converts string route parameters to numbers?
Using the unary plus operator, e.g., `+params.get('id')`
Can routerLink handle dynamic URL segments? Provide an example.
Yes, e.g., `<a [routerLink]='['/profile', username]'>Profile</a>`
Previous
Next