Bird
0
0

Given this container component code:

medium📝 component behavior Q4 of 15
Angular - Advanced Patterns
Given this container component code:
export class ContainerComponent {
  items = ['apple', 'banana'];
}

And presentational component template:
<ul>
  <li *ngFor="let item of items">{{ item }}</li>
</ul>

What will be rendered if the container passes items to the presentational component?
AError: items not defined
B<ul><li>items</li></ul>
C<ul></ul>
D<ul><li>apple</li><li>banana</li></ul>
Step-by-Step Solution
Solution:
  1. Step 1: Understand data flow

    The container passes the array ['apple', 'banana'] as 'items' to the presentational component.
  2. Step 2: Analyze template rendering

    The presentational component loops over 'items' and creates a list item for each element.
  3. Final Answer:

    <ul><li>apple</li><li>banana</li></ul> -> Option D
  4. Quick Check:

    Passing array renders list items [OK]
Quick Trick: ngFor loops over passed array to render list [OK]
Common Mistakes:
  • Expecting string 'items' to render
  • Forgetting to pass data from container
  • Assuming empty list if not passed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes