Bird
0
0

Why does this component fail to project content?

medium📝 Debug Q7 of 15
Angular - Component Interaction
Why does this component fail to project content?
Component template:
<div>
  <ng-content select=".main"></ng-content>
</div>

Usage:
<my-comp>
  <p class="content">Hello</p>
</my-comp>
Ang-content requires an id selector, not class.
BContent projection only works with <span> tags.
CThe projected element's class does not match the select attribute.
DThe component template must have multiple ng-content tags.
Step-by-Step Solution
Solution:
  1. Step 1: Compare select attribute and projected content

    The template selects elements with class 'main', but usage provides class 'content'.
  2. Step 2: Understand projection matching

    Content only projects if selector matches; here it does not, so nothing appears.
  3. Final Answer:

    The projected element's class does not match the select attribute. -> Option C
  4. Quick Check:

    Selector mismatch blocks projection = B [OK]
Quick Trick: Selector must match projected element's class exactly [OK]
Common Mistakes:
  • Assuming any content projects regardless of selector
  • Thinking ng-content requires id selectors
  • Believing projection depends on tag type

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes