Skip to content

Commit

Permalink
fix: don't instantiate providers with ngOnDestroy eagerly. (angular#1…
Browse files Browse the repository at this point in the history
…5070)

BREAKING CHANGE:

Perviously, any provider that had an ngOnDestroy lifecycle hook would be created eagerly.

Now, only classes that are annotated with @component, @directive, @pipe, @NgModule are eager. Providers only become eager if they are either directly or transitively injected into one of the above.

This also makes all `useValue` providers eager, which
should have no observable impact other than code size.

EXPECTED IMPACT:
Making providers eager was an incorrect behavior and never documented.
Also, providers that are used by a directive / pipe / ngModule stay eager.
So the impact should be rather small.

Fixes angular#14552
  • Loading branch information
tbosch authored and chuckjaz committed Mar 14, 2017
1 parent 46a1190 commit 3d88e5d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/router_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ export function routerNgProbeToken() {
*/
@NgModule({declarations: ROUTER_DIRECTIVES, exports: ROUTER_DIRECTIVES})
export class RouterModule {
constructor(@Optional() @Inject(ROUTER_FORROOT_GUARD) guard: any) {}
// Note: We are injecting the Router so it gets created eagerly...
constructor(@Optional() @Inject(ROUTER_FORROOT_GUARD) guard: any, @Optional() router: Router) {}

/**
* Creates a module with all the router providers and directives. It also optionally sets up an
Expand Down

0 comments on commit 3d88e5d

Please sign in to comment.