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 fired when service is provided using useFactory #14818

Copy link
Copy link
Closed
@colinkahn

Description

@colinkahn
Issue body actions

I'm submitting a ... (check one with "x")

[ ] bug report => search github for a similar issue or PR before submitting
[x] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior
When you provide a service using useFactory, ngOnDestroy will never be called.

Expected behavior
Regardless of how you provide the service, ngOnDestroy should get called if it is a method on the service.

Minimal reproduction of the problem with instructions
https://plnkr.co/edit/aUaz6ewyM3m5JorsAoCO?p=preview

  1. Open the console.
  2. Click the "Create Component" button one or many times
  3. After a 2 second delay the component will be destroyed, but no console output will be seen.
  4. If you replace useFactory with useClass the problem goes away and you'll see output.

What is the motivation / use case for changing the behavior?
There are many cases, main motivator is that this isn't intuitive.

Please tell us about your environment:

  • Angular version: 2.4.8
  • Browser: Chrome 56.0.2924.87
  • Language: TypeScript 2.0

  • Node (for AoT issues): node --version =

kemsky, seangwright, nook-ru, sgkazakov, dimakuba and 2 more

Metadata

Metadata

Assignees

No one assigned

    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.