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 container component in Angular?
A container component manages data and logic. It fetches data, handles user actions, and passes data to presentational components. It does not focus on how things look.
Click to reveal answer
beginner
What is a presentational component in Angular?
A presentational component focuses on how things look. It receives data via inputs and emits events via outputs. It does not manage data fetching or business logic.
Click to reveal answer
intermediate
Why separate container and presentational components?
Separating them makes code easier to read and maintain. Containers handle logic, presentational components handle UI. This separation helps reuse UI parts and test logic separately.
Click to reveal answer
intermediate
How do container components communicate with presentational components in Angular?
Container components pass data to presentational components using @Input properties. Presentational components send events back using @Output EventEmitters.
Click to reveal answer
beginner
Give an example of a presentational component's role.
A presentational component might display a list of items with buttons. It shows the items it receives and emits an event when a button is clicked, without knowing where data comes from.
Click to reveal answer
What is the main responsibility of a container component?
AManage data and business logic
BDisplay UI and styles
COnly emit events
DHandle CSS styling
✗ Incorrect
Container components handle data fetching and business logic, not just UI or styling.
How does a presentational component receive data?
ABy fetching from a service
BVia @Input properties
CUsing @Output EventEmitters
DDirectly from the DOM
✗ Incorrect
Presentational components get data through @Input properties passed from container components.
Which component should handle user interaction logic?
ABoth equally
BPresentational component
CContainer component
DNeither
✗ Incorrect
Container components handle user interaction logic and pass data/events to presentational components.
What does a presentational component emit to notify events?
A@Input property
BDirect DOM event
CService call
D@Output EventEmitter
✗ Incorrect
Presentational components use @Output EventEmitter to send events back to container components.
Why is separating container and presentational components helpful?
The presentational component expects data from parent, so item must be decorated with @Input() to receive it.
Step 2: Verify template and selector
Template syntax and selector are valid; no abstract class needed.
Final Answer:
Missing @Input() decorator on item property -> Option A
Quick Check:
@Input() needed to receive data [OK]
Hint: Add @Input() to receive data in presentational component [OK]
Common Mistakes:
Forgetting @Input() on input properties
Thinking template interpolation is wrong
Assuming selector must be different
5. You want to create a container component that fetches a list of products and passes it to a presentational component for display. Which approach best follows Angular container and presentational component patterns?
hard
A. Container fetches products, stores in a variable, passes via @Input(); presentational only displays list
B. Presentational component fetches products and emits events to container
C. Container and presentational both fetch products independently
D. Presentational component manages fetching and state internally
Solution
Step 1: Identify container responsibility
The container should handle fetching data and managing state.
Step 2: Identify presentational responsibility
The presentational component should only display data received via @Input() without fetching or managing state.
Final Answer:
Container fetches products, stores in a variable, passes via @Input(); presentational only displays list -> Option A
Quick Check:
Container = data fetch, Presentational = display [OK]
Hint: Container fetches data, presentational displays it [OK]