Skip to content

ngOnDestroy not fired when service is provided using useFactory #14818

Description

@colinkahn

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 =

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions