Skip to content
0:00 / 0:00

#angular#dependency-injection#tree-shaking

Angular 6 { providedIn: 'root' }

webdave_de

208 subscribers • 1 video on Hallway

YouTube
  • Recommended by 1 person: 1 on Stack Overflow and its sister sites.
  • May be out of date. The tools, versions or practices it shows have likely moved on.

Intermediate. Assumes working knowledge.

1.8K views8 years ago1 recommendation

Web developmentVue, Svelte, Angular and others

An explanation and demonstration of using the providedIn root syntax for services in Angular 6.

The uploader added no description.

Why it's here

1 person recommends this

What people say. Recommended for understanding how Angular's tree-shakable providers work.

DeborahKon Stack Overflow • Recommends

On “Angular 6 providedin doesn't work -> StaticInjectorError”

98% of the time, use providedIn = 'root'. It will register the service with the root application injector, will be tree shaken, and will be available to any component that needs it. The tree shaking will ensure the service is only included in the bundles where it is used. Use the providers array in a component if the service only needs to be provided in the component and its nested children. (For service isolation at the component level or if you need multiple instances of the service per component.) Don't use the providers array in a module (this is old syntax and it no longer recommended) Use providedIn='lazymodule' if you want to limit access to a service to a particular lazy loaded…