0

I have a function that takes a component instance and overrides the ngOnDestroy hook:

export function patch(instance) {
 instance['ngOnDestroy'] = function() {
   console.log('ngOnDestroy');
  }
}

And in the component:

  ngOnInit() {
    patch(this);
  }

But I don't see the log when the component is destroyed. Why it's not working?

Jeff Mercado
  • 129,526
  • 32
  • 251
  • 272
undefined
  • 6,366
  • 12
  • 46
  • 90

1 Answers1

3

The ViewEnging runs methods directly from the component instance. On the opposite Ivy collect all life cycle methods in the view of the component at the beginning of the component creation so future changes will not have affect at all.

Maciej Sikorski
  • 743
  • 5
  • 16
  • I have the same problem even when trying to patch it in constructor. Is this also expected behavior then? – jlang Nov 12 '20 at 16:47