Bird
0
0

Identify the error in this Angular component code:

medium📝 Debug Q14 of 15
Angular - TypeScript in Angular
Identify the error in this Angular component code:
export class DemoComponent {
  private title = 'Hello';
}

// In template:
// <h1>{{ title }}</h1>
ATemplate cannot access private property 'title'
BNo error, code works fine
CMissing semicolon after title declaration
Dtitle should be declared as protected
Step-by-Step Solution
Solution:
  1. Step 1: Check property access modifier

    title is declared private, so it is hidden from outside the class.
  2. Step 2: Understand template access rules

    Angular templates can only access public properties, so trying to use title in template causes an error.
  3. Final Answer:

    Template cannot access private property 'title' -> Option A
  4. Quick Check:

    Private properties are not accessible in templates [OK]
Quick Trick: Templates only see public, not private properties [OK]
Common Mistakes:
  • Ignoring access modifier effect on templates
  • Thinking missing semicolon causes error
  • Confusing protected with private for template access

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes