How do you inject a service into an Angular component?
- In the component's constructor
- Using HTML attributes
- Via @NgModule metadata
- With an external JavaScript file
You inject a service into an Angular component by including it as a parameter in the component's constructor. This allows the component to use the service's methods and properties.
Loading...
Related Quiz
- In an Angular application, how can you optimize a component to be checked only once by Angular's change detection mechanism?
- Which Angular CLI command is used to generate a new component?
- To apply a function to each item emitted by an Observable, you use the _____ operator in RxJS.
- To test a component as a whole, including its interaction with child components, you should use _____ testing.
- To guard a route against unauthorized access, you can implement a custom class that implements the _____ interface.