tezvyn:

Angular Component Lifecycle Hooks

Source: angular.devbeginner

Angular's lifecycle hooks are callbacks for a component's life events: creation, updates, and destruction. Use ngOnInit for one-time setup after inputs are ready, and ngOnChanges to react to input changes. The footgun: don't use the constructor for setup.

Angular's lifecycle hooks are callbacks for a component's key life events: creation, updates, and destruction. They give you predictable moments to run code, like fetching data or updating state. Use ngOnInit for one-time setup after all inputs are initialized, and ngOnChanges to react when those inputs change. The common footgun is putting setup logic that depends on input properties in the constructor. Inputs are not available there; use ngOnInit for this work to avoid errors.

Read the original → angular.dev

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

Angular Component Lifecycle Hooks · Tezvyn