When building modern applications, choosing the right architecture is crucial for scalability, maintainability, and testability. Two popular patterns, MVVM (Model-View-ViewModel) and MVP (Model-View-Presenter):
#MVVM#architecture
Stop Overusing ngOnInit! 🚫
I'm seeing A LOT initilized there.
In modern #Angular, you don’t need ngOnInit for everything - especially with Signals!
[ Recommendation ]
Use class field initialization as
your go-to for simple setups:
- Observables
- Constants
- Forms
- Signals
etc.
[ Execution Order ]
Class Field Initialization:
– Runs first
Constructor:
– Runs second
ngOnInit:
– Runs last ( out of these 3 )
- use for inputs
- .subscribe but really try not to do it
[ Class field vs Constructor ]
For most cases.
There’s no difference between
class field and constructor initialization
Class fields are just cleaner and execute first.
Preference.
With Signals, you can pretty much
skip lifecycle hooks entirely!
🔥The biggest #Angular conference in Europe is back!
Join the 9th edition of @ngPolandConf with an incredible lineup of speakers!
🗓️Workshops: Nov 5, 2024
🗓️ NG Poland: Nov 6, 2024
🗓️ JS Poland: Nov 7, 2024
🔗 https://t.co/CYxSICf8WW
⌛️ Round 2 tickets available until Sept 27th!
#NGPoland #AngularCommunity
👩💻 Accelerate your workflow with our latest development tools.
See the latest updates to our tools, recent releases, and new features from #GoogleIO → https://t.co/H107Mspl1t