Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

ngOnDestroy not called for injectables created via factory providers #22466

Copy link
Copy link
Closed
@IgorMinar

Description

@IgorMinar
Issue body actions

Current behavior

export class DestroyTest implements OnDestroy {
  ngOnDestroy() {  // <<<<< this method is NEVER called
    console.log('ngOnDestroy DestroyTest called');
  }
}

export class DestroyTest2 implements OnDestroy {
  ngOnDestroy() { // <<<<< this method IS called when the app ref is being destroyed
    console.log('ngOnDestroy DestroyTest2 called');
  }
}

export function createDestroyTest() {
  return new DestroyTest();
}

@NgModule({
  imports:      [ BrowserModule, FormsModule ],
  declarations: [ AppComponent, HelloComponent ],
  bootstrap:    [ AppComponent ],
  providers: [
    {provide: DestroyTest, useFactory: createDestroyTest},
    DestroyTest2
  ]
})
export class AppModule {
  constructor(
    destroyTest1: DestroyTest, destroyTest2: DestroyTest2) {}
}

Expected behavior

the ngOnDestroy method, if present, should be called on all values provided via DI regardless of the provider type.

Minimal reproduction of the problem with instructions

https://stackblitz.com/edit/angular-h15slp

Environment


Angular version: 6.0.0-beta.x

// Note: reported by GX

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.