Bird
0
0

Which of the following is the correct way to specify the HTML template inline in a component decorator?

easy📝 Syntax Q12 of 15
Angular - Components
Which of the following is the correct way to specify the HTML template inline in a component decorator?
A<code>@Component({ template: '<h1>Hello</h1>' })</code>
B<code>@Component({ templateUrl: './app.component.html' })</code>
C<code>@Component({ templateFile: 'app.component.html' })</code>
D<code>@Component({ htmlTemplate: '<h1>Hello</h1>' })</code>
Step-by-Step Solution
Solution:
  1. Step 1: Recall the difference between template and templateUrl

    template is for inline HTML, templateUrl is for external file path.
  2. Step 2: Identify the correct syntax for inline template

    Only template: '

    Hello

    '
    is valid for inline HTML.
  3. Final Answer:

    @Component({ template: '<h1>Hello</h1>' }) -> Option A
  4. Quick Check:

    Inline HTML uses template property = A [OK]
Quick Trick: Use 'template' for inline HTML, 'templateUrl' for files [OK]
Common Mistakes:
  • Using templateUrl with inline HTML
  • Using wrong property names like templateFile
  • Confusing template and htmlTemplate

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes