Using ngClass for Dynamic Classes in Angular
📖 Scenario: You are building a simple Angular component that displays a list of tasks. Each task can be marked as completed or pending. You want to highlight completed tasks with a green background and pending tasks with a yellow background.
🎯 Goal: Create an Angular standalone component that uses ngClass to dynamically apply CSS classes based on each task's completion status.
📋 What You'll Learn
Create a list of tasks with exact names and completion status
Add a boolean variable to track if a task is completed
Use
ngClass to apply CSS classes dynamicallyAdd CSS classes for completed and pending tasks
Use a standalone Angular component with signals and new control flow
💡 Why This Matters
🌍 Real World
Dynamic styling is common in real apps to show status, errors, or user actions visually. Using ngClass helps keep templates clean and maintainable.
💼 Career
Understanding ngClass and dynamic styling is essential for Angular developers to build interactive and accessible user interfaces.
Progress0 / 4 steps