javascript / beginner
Snippet
Initializing Logic with ngOnInit
ngOnInit is a lifecycle hook called after Angular has finished initializing the component's data-bound properties. It is the best place for startup logic like API calls.
snippet.js
1
2
3
ngOnInit(): void {this.fetchData();}
angular
Breakdown
1
ngOnInit(): void
Defines the standard Angular lifecycle method that returns nothing.
2
this.fetchData()
Executes a function to load data as soon as the component is ready.