question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OnDestroy override issue - Angular 9+

See original GitHub issue

🐞 bug report

Affected Package

The issue is caused by package **@angular/core**

Is this a regression?

Yes, the previous version in which this bug was not present was: **Angular 8**

Description

Consider a @Component what implements OnDestroy, on the constructor there is a case I must set the following code:

this.OnDestroy = ()=>{ alert(β€˜Invoke’); }

On Angular 8, it use to work, but somehow in Angular 9 (maybe its IVE issue) that not entering to the override func, instead it entering to the initial implemented func.

Can you explain why and if it really a bug?

🌍 Your Environment

Angular Version:




Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.901.6
@angular-devkit/core         9.1.6
@angular-devkit/schematics   9.1.6
@schematics/angular          9.1.6
@schematics/update           0.901.6
rxjs                         6.5.4

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
petebacondarwincommented, Jul 14, 2020

This is kind of a duplicate of https://github.com/angular/angular/issues/30497, which is fixed by https://github.com/angular/angular/pull/35464. But in your case, you appear to be changing the onDestroy() method on the instance, whereas that PR will only allow you to change the method on the prototype.

I think you could workaround this right now by creating your class like:

@Component(...)
export class MyComponent implements NgOnDestroy {
  onDestroy() {
    this._onDestroy();
  }

  private _onDestroy() {}

  constructor() {
    this._onDestroy = () => {
      alert('Invoke');
    };
  }
}
0reactions
angular-automatic-lock-bot[bot]commented, Aug 27, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

A Deep Dive into Angular's NgOnDestroy - Wesley Grimes
NgOnDestroy is a lifecycle method that can be added by implementing OnDestroy on the class and adding a new class method named ngOnDestroy...
Read more >
angular - Ensure super.onDestroy() in derived component
Most OOP languages dont offer the feature that you are looking for. Once a method is overriden by a child class, there is...
Read more >
OnDestroy - Angular
A lifecycle hook that is called when a directive, pipe, or service is destroyed. Use for any custom cleanup that needs to occur...
Read more >
How to auto-unsubscribe in Angular 9 | by Andres Gesteira
We are going to need to modify a property that belongs to cmp : onDestroy . The problem is that that property is...
Read more >
How to Share Lifecycle Methods Between Components in ...
Fortunately, that's possible, as of Angular 9; simply remove BaseComponent 's @Component selector property and it won't register a new tag.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found