You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
This is kind of a duplicate of #30497, which is fixed by #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:
@petebacondarwin there is no way to use arrow functions in general as lifecycle hooks, is there?
Is this because of some framework issue (inheritance) or is it a Typescript issue? It's just for aesthetics, doing hooks as regular functions and all other methods as fat arrow functions just looks weird to my ocd brain ;)
Sorry @spock123 - I am still not sure what the problem is here. The ngOnInit() method must be defined (even after #35464) before the app bootstraps. The following works for me:
This syntax is just a bit. .. weird.. having to add it to the prototype is not what I had in mind, I just wanted to use the fat arrow syntax directly in the component when creating component hooks.
But this is really hijacking this issue, I'm sorry for the derailing. I'll experiment more with how to use fat arrow functions.
Activity
petebacondarwin commentedon Jul 14, 2020
This is kind of a duplicate of #30497, which is fixed by #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:
spock123 commentedon Jul 22, 2020
@petebacondarwin there is no way to use arrow functions in general as lifecycle hooks, is there?
Is this because of some framework issue (inheritance) or is it a Typescript issue? It's just for aesthetics, doing hooks as regular functions and all other methods as fat arrow functions just looks weird to my ocd brain ;)
petebacondarwin commentedon Jul 23, 2020
@spock123 - I don't understand the question here. Could you give a concrete example of what is not working for you?
spock123 commentedon Jul 23, 2020
@petebacondarwin I'm sorry I did not intend to hijack this issue but I guess it's somewhat related:
If I have a component with the following code ngOnInit method:
ngOnInit = () => console.log('Hello Init');However this will be called:
ngOnInit() { console.log('Hello Init'); }I was just wondering if it was somehow possible to use fat arrow functions when creating component lifecycle hooks
petebacondarwin commentedon Jul 24, 2020
Sorry @spock123 - I am still not sure what the problem is here. The
ngOnInit()method must be defined (even after #35464) before the app bootstraps. The following works for me:spock123 commentedon Jul 24, 2020
@petebacondarwin thank you for your explanation.
This syntax is just a bit. .. weird.. having to add it to the prototype is not what I had in mind, I just wanted to use the fat arrow syntax directly in the component when creating component hooks.
But this is really hijacking this issue, I'm sorry for the derailing. I'll experiment more with how to use fat arrow functions.
Cheers
petebacondarwin commentedon Jul 24, 2020
Using it directly in the component is effectively the same as doing it in the constructor. This has two problems:
pkozlowski-opensource commentedon Jul 27, 2020
This currently works as designed - I've opened a new feature request with more info: #38241
angular-automatic-lock-bot commentedon 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.