8000 ngOnDestroy not called on service declared using useClass · Issue #28857 · angular/angular · GitHub
[go: up one dir, main page]

Skip to content

ngOnDestroy not called on service declared using useClass #28857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8000 Closed
Humberd opened this issue Feb 20, 2019 · 4 comments
Closed

ngOnDestroy not called on service declared using useClass #28857

Humberd opened this issue Feb 20, 2019 · 4 comments
Labels
area: core Issues related to the framework runtime core: di freq3: high type: bug/fix
Milestone

Comments

@Humberd
Copy link
Member
Humberd commented Feb 20, 2019

🐞 bug report

Affected Package

The issue is caused by package @angular/core

Is this a regression?

I don't know

Description

When declaring a service as a component provider by the structure below Angular doesn't call ngOnDestroy method declared in BaseClass when a component is being destroyed.

abstract class BaseClass implements OnDestroy {
	ngOnDestroy() {
		console.log('destroying'); //this is not called
	}	
}

class FooClass extends BaseClass {
}
{
	provide: BaseClass,
	useClass: FooClass
}

🔬 Minimal Reproduction

https://stackblitz.com/edit/angular-service-destroy

🌍 Your Environment

Angular Version:

@angular-devkit/architect         0.11.3
@angular-devkit/build-angular     0.11.3
@angular-devkit/build-optimizer   0.11.3
@angular-devkit/build-webpack     0.11.3
@angular-devkit/core              7.1.3
@angular-devkit/schematics        7.1.3
@angular/cdk                      7.1.1
@angular/material                 7.1.1
@ngtools/webpack                  7.1.3
@schematics/angular               7.1.3
@schematics/update                0.11.3
rxjs                              6.2.2
typescript                        3.1.6
webpack                           4.23.1

But it also appears on 7.2.5

@pkozlowski-opensource pkozlowski-opensource added the area: core Issues related to the framework runtime label Feb 20, 2019
@ngbot ngbot bot added this to the needsTriage milestone Feb 20, 2019
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Apr 18, 2019
@jlfeld1
Copy link
jlfeld1 commented Jul 12, 2019

This is also occurring in 8.0.0

@trotyl
Copy link
Contributor
trotyl commented Jul 17, 2019

Duplicate of #14821, #28738


The problem is not about abstract class, but being provided at component level.

@Component({
  selector: 'hello',
  template: `Provider component`,
  providers: [
    FirstChildClass,
    {
      provide: BaseClass,
      useClass: SecondChildClass
    }
  ]
})

@kara
Copy link
Contributor
kara commented May 27, 2020

Yep, this looks like a duplicate of #14821. Let's track the issue there.

@kara kara closed this as completed May 27, 2020
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jun 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: core Issues related to the framework runtime core: di freq3: high type: bug/fix
Projects
None yet
Development

No branches or pull requests

6 participants
0