Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is a smart component in Angular?
A smart component manages data and logic. It fetches data, handles user actions, and passes data to dumb components. Think of it as the brain controlling the app's behavior.
Click to reveal answer
beginner
What is a dumb component in Angular?
A dumb component only displays data and emits events. It does not manage data or logic. It’s like a simple display or form that relies on smart components for data.
Click to reveal answer
intermediate
Why use the smart and dumb component pattern?
It separates concerns: smart components handle logic and data, dumb components handle UI. This makes code easier to read, test, and reuse, like having a manager and workers each with clear jobs.
Click to reveal answer
intermediate
How do smart and dumb components communicate in Angular?
Smart components pass data to dumb components using @Input properties. Dumb components send events back using @Output EventEmitters. This is like sending messages back and forth clearly.
Click to reveal answer
beginner
Give an example of a dumb component's responsibility.
A dumb component might show a list of items and emit an event when an item is clicked. It does not fetch or change the list, just shows it and tells the smart component what happened.
Click to reveal answer
What is the main role of a smart component?
AOnly display UI without logic
BManage data and business logic
CEmit events without receiving data
DStyle the application
✗ Incorrect
Smart components handle data fetching, logic, and pass data to dumb components.
How does a dumb component receive data from a smart component?
AUsing Angular routing
BUsing @Output EventEmitters
CDirectly accessing services
DUsing @Input properties
✗ Incorrect
Dumb components receive data via @Input properties from smart components.
Which of the following is NOT a characteristic of dumb components?
ADisplay data
BEmit user events
CFetch data from APIs
DHave no business logic
✗ Incorrect
Dumb components do not fetch data; smart components handle that.
Why is separating smart and dumb components helpful?
AImproves code clarity and reuse
BMakes components bigger
CRemoves the need for services
DAvoids using Angular directives
✗ Incorrect
Separation helps keep code clean, easier to test, and reuse components.
How do dumb components notify smart components about user actions?
AUsing @Output EventEmitters
BUsing @Input properties
CBy calling smart component methods directly
DBy changing global variables
✗ Incorrect
Dumb components emit events with @Output to notify smart components.
Explain the difference between smart and dumb components in Angular.
Think about who controls data and who just shows it.
You got /4 concepts.
Describe how smart and dumb components communicate and why this pattern is useful.
Consider the flow of data and events between components.
You got /4 concepts.
Practice
(1/5)
1. What is the main role of a smart component in Angular's smart and dumb component pattern?
Assuming missing decorators cause runtime error here
Ignoring event binding from dumb to smart
4. Identify the error in this dumb component code that prevents it from emitting events to the smart component:
@Component({
selector: 'app-dumb',
template: `<button (click)="clicked.emit()">Click</button>`
})
export class DumbComponent {
clicked = new EventEmitter<void>();
}
medium
A. EventEmitter should be imported from '@angular/core/testing'
B. Missing @Output() decorator on the clicked property
C. The template syntax for click event is incorrect
D. The clicked property should be a function, not EventEmitter
Solution
Step 1: Check event emitter declaration
The clicked property must have @Output() decorator to emit events to parent.
Step 2: Verify imports and syntax
EventEmitter is correctly imported from '@angular/core', template syntax is correct.
Final Answer:
Missing @Output() decorator on the clicked property -> Option B
Quick Check:
@Output() missing = no event emission [OK]
Hint: Always add @Output() to EventEmitter properties [OK]
Common Mistakes:
Forgetting @Output() decorator
Importing EventEmitter from wrong package
Miswriting template event binding syntax
5. You want to refactor a large Angular component that mixes data fetching, logic, and UI display into smart and dumb components. Which approach best follows the smart and dumb component pattern?
hard
A. Create a smart component to fetch data and handle logic, pass data via @Input() to dumb components that only display UI and emit events
B. Move all logic and data fetching into dumb components and keep smart components only for styling
C. Combine smart and dumb components into one to reduce complexity
D. Use dumb components to fetch data and smart components to display UI
Solution
Step 1: Separate concerns by responsibility
Smart components should handle data fetching and logic, dumb components focus on UI and user interaction.
Step 2: Use Angular bindings correctly
Pass data from smart to dumb via @Input() and receive events via @Output().
Final Answer:
Create a smart component to fetch data and handle logic, pass data via @Input() to dumb components that only display UI and emit events -> Option A
Quick Check:
Smart = logic/data, Dumb = UI only [OK]
Hint: Smart handles data/logic; dumb handles UI and events [OK]