Which of the following selectors can be used to define an Angular component?
easy📝 Conceptual Q2 of 15
Angular - Components
Which of the following selectors can be used to define an Angular component?
Aselector: 'app-header'
Bselector: '#appHeader'
Cselector: '123app'
Dselector: 'app header'
Step-by-Step Solution
Solution:
Step 1: Understand Angular selector rules
Angular component selectors must be valid CSS selectors and cannot start with a number or contain spaces.
Step 2: Evaluate each option
selector: 'app-header' is a valid element selector. selector: '#appHeader' uses an ID selector which is invalid for components. selector: '123app' starts with a number, invalid. selector: 'app header' contains a space, invalid.
Final Answer:
selector: 'app-header' -> Option A
Quick Check:
Valid CSS selector without spaces or invalid characters [OK]
Quick Trick:Component selectors must be valid CSS selectors without spaces [OK]
Common Mistakes:
Using spaces in selectors
Starting selectors with numbers
Using ID selectors for components
Master "Components" in Angular
9 interactive learning modes - each teaches the same concept differently