A client asks you to highlight the currently active page link in the navigation menu. How would you achieve this in Angular?
- By using the routerLinkActive directive and applying it to the navigation menu items with a CSS class.
- By using JavaScript to detect the active route and apply a CSS class to the corresponding navigation menu item.
- By manually updating the active page link in the navigation component whenever a route changes.
- By creating a custom Angular directive to handle active link highlighting.
To highlight the currently active page link in the navigation menu in Angular, you should use the routerLinkActive directive. This directive is applied to the navigation menu items and automatically adds a CSS class when the corresponding route is active. The other options are either incorrect or involve more manual and error-prone approaches.
Loading...
Related Quiz
- How can you simulate a click event on an element during Angular unit testing?
- A client asks for a feature where certain parts of the application should only be accessible to authenticated users. Which feature of Angular would you use to implement this?
- When dealing with a custom component that doesn't naturally fit into Angular's form ecosystem, which strategy can be employed to ensure it works with ngModel and formControl directives?
- How can you configure different environments (e.g., development, production) in an Angular application using Angular CLI?
- You notice that certain components in your application are re-rendered even when their input data remains unchanged. What could be a potential solution to optimize this behavior?