Bird
0
0

How do you correctly define an inline template within an Angular component decorator?

easy📝 Syntax Q3 of 15
Angular - Components
How do you correctly define an inline template within an Angular component decorator?
A@Component({ selector: 'app-test', template: `
Hello World
` })
B@Component({ selector: 'app-test', templateUrl: 'test.component.html' })
C@Component({ selector: 'app-test', template = `
Hello World
` })
D@Component({ selector: 'app-test', templateFile: 'test.component.html' })
Step-by-Step Solution
Solution:
  1. Step 1: Identify the decorator property for inline templates

    The correct property is template, which accepts a string or template literal.
  2. Step 2: Check syntax correctness

    @Component({ selector: 'app-test', template: `
    Hello World
    ` }) uses template with backticks for multi-line HTML, which is valid.
  3. Step 3: Eliminate incorrect options

    @Component({ selector: 'app-test', templateUrl: 'test.component.html' }) uses templateUrl which is for external templates, not inline.
    @Component({ selector: 'app-test', template = `
    Hello World
    ` }) uses an assignment operator = inside the decorator, which is invalid.
    @Component({ selector: 'app-test', templateFile: 'test.component.html' }) uses a non-existent property templateFile.
  4. Final Answer:

    @Component({ selector: 'app-test', template: `
    Hello World
    ` })
    -> Option A
  5. Quick Check:

    Inline templates use template property with string literals [OK]
Quick Trick: Use 'template' property with backticks for inline templates [OK]
Common Mistakes:
  • Using 'templateUrl' instead of 'template' for inline templates
  • Using '=' instead of ':' in decorator properties
  • Using non-existent properties like 'templateFile'

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes