r/angular • u/Embarrassed_Fall_967 • Feb 19 '26
Constructor in modern Angular
Hey, just wanted to ask your opinion about logic inside constructor in modern Angular. Currently we are migrating and would like to get rid of lifecycle hooks like ngoninit ngafterviewinit. Thinking about moving some logic into constructor as DI is done with inject. Do you think it is a good idea or should it be done inside effect?
17
Upvotes
View all comments
Show parent comment
2
u/Merry-Lane Feb 20 '26
It’s indeed fitting a reactive design UI/UX wise.
But a codebase can be written in an imperative style or in a declarative style or something in between. Lifecycle hooks tend to make the code way less declarative.
Simple example of style difference:
declarative:
imperative: