Bird
0
0

Identify the error in this Angular component code:

medium📝 Debug Q6 of 15
Angular - Components
Identify the error in this Angular component code:
@Component({ templateUrl: './app.component.html' }) export class AppComponent { template: '

Hello

'; }
AThe 'templateUrl' path must be an absolute URL
BThe component must use 'template' instead of 'templateUrl'
CThe 'template' property inside the class is invalid
DThe class must not have any properties
Step-by-Step Solution
Solution:
  1. Step 1: Analyze component decorator and class

    The decorator uses 'templateUrl' correctly for external template.
  2. Step 2: Check class property usage

    Defining 'template' as a class property is invalid; templates belong in decorator only.
  3. Final Answer:

    The 'template' property inside the class is invalid -> Option C
  4. Quick Check:

    Templates belong in decorator, not class properties [OK]
Quick Trick: Templates go in decorator, not class properties [OK]
Common Mistakes:
  • Confusing class properties with decorator metadata
  • Thinking templateUrl needs absolute URL
  • Believing class cannot have properties

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes