If a service is provided both at the module level and the component level, which instance will the component receive?

  • The component will receive both instances.
  • The component will receive the component-level instance.
  • The component will receive the module-level instance.
  • The component will throw an error.
In Angular (or similar frameworks), when a service is provided both at the module and component levels, the component will receive the component-level instance. This is known as "shadowing." The component-level instance takes precedence over the module-level one. The scenario where a component receives both instances is not valid, and it will result in an error.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *