Bird
0
0

You want to switch an Angular component from an inline template to an external template. Which steps should you follow?

hard📝 component behavior Q8 of 15
Angular - Components
You want to switch an Angular component from an inline template to an external template. Which steps should you follow?
AKeep 'template', add 'templateUrl' with file path, Angular merges both
BAdd both 'template' and 'templateUrl' to support fallback
CReplace 'templateUrl' with 'template' and write HTML inline
DRemove 'template', add 'templateUrl' with file path, move HTML to that file
Step-by-Step Solution
Solution:
  1. Step 1: Remove inline template property

    Remove the 'template' property from the component decorator to avoid conflicts.
  2. Step 2: Add 'templateUrl' with external file path

    Add 'templateUrl' pointing to the external HTML file containing the template.
  3. Step 3: Move HTML content to the external file

    Place the HTML markup from inline template into the external file referenced by 'templateUrl'.
  4. Final Answer:

    Remove 'template', add 'templateUrl' with file path, move HTML to that file -> Option D
  5. Quick Check:

    Switch inline to external by replacing template with templateUrl [OK]
Quick Trick: Remove inline template, add templateUrl with file [OK]
Common Mistakes:
  • Keeping both template and templateUrl
  • Expecting Angular to merge templates
  • Adding both for fallback support

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes