Bird
0
0

Given this code, what will be the output when AppComponent is rendered?

medium📝 component behavior Q13 of 15
Angular - Standalone Components
Given this code, what will be the output when AppComponent is rendered?
@Component({ selector: 'app-root', standalone: true, template: `

Hello

`, imports: [ChildComponent] }) export class AppComponent {}
@Component({ selector: 'app-child', standalone: true, template: `

Child works!

` }) export class ChildComponent {}
A<h1>Hello</h1><p>Child works!</p>
B<h1>Hello</h1>
CError: ChildComponent not declared in NgModule
D<p>Child works!</p>
Step-by-Step Solution
Solution:
  1. Step 1: Check how ChildComponent is included

    AppComponent imports ChildComponent in its imports array, allowing usage in its template.
  2. Step 2: Understand standalone component rendering

    Both components are standalone, so ChildComponent renders inside AppComponent's template.
  3. Final Answer:

    <h1>Hello</h1><p>Child works!</p> -> Option A
  4. Quick Check:

    Standalone imports enable nested component rendering [OK]
Quick Trick: Standalone components must be imported to use in templates [OK]
Common Mistakes:
  • Assuming child renders without importing
  • Expecting NgModule declaration errors
  • Ignoring standalone imports array

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes