When to use OnPush
📖 Scenario: You are building a simple Angular app that shows a list of tasks. Each task has a name and a status. You want to make the app faster by telling Angular when to update the task list component.
🎯 Goal: Learn how to use the OnPush change detection strategy in Angular to improve performance by updating the component only when its input data changes.
📋 What You'll Learn
Create a standalone Angular component called
TaskListComponent that displays a list of tasks.Add a configuration variable to set the change detection strategy to
OnPush.Use an
@Input() property called tasks to receive the list of tasks.Add a button in the parent component to update the tasks list immutably and see the effect of
OnPush.💡 Why This Matters
🌍 Real World
Using <code>OnPush</code> helps Angular apps run faster by reducing unnecessary updates. This is important in apps with many components or complex UI.
💼 Career
Understanding change detection strategies like <code>OnPush</code> is key for Angular developers to write efficient, scalable applications.
Progress0 / 4 steps