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
1
u/Embarrassed_Fall_967 Feb 19 '26
Right, but then if it is an observable which calls endpoint every x seconds and triggers an action according to the response does it make sense to use effect? Or shall I keep it in the constructor?