0
0
Angularframework~5 mins

Component decorator and metadata in Angular - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the @Component decorator in Angular?
The @Component decorator marks a class as an Angular component and provides metadata that tells Angular how to process, instantiate, and use the component in the app.
Click to reveal answer
beginner
Name three common metadata properties used inside the @Component decorator.
Common metadata properties include:<br>- selector: the HTML tag to use the component<br>- templateUrl or template: the HTML view for the component<br>- styleUrls or styles: CSS styles for the component
Click to reveal answer
beginner
How does the 'selector' property in @Component metadata affect the component?
The 'selector' defines the custom HTML tag that represents the component. When Angular sees this tag in HTML, it creates and inserts the component there.
Click to reveal answer
intermediate
What is the difference between 'template' and 'templateUrl' in component metadata?
'template' contains inline HTML code as a string inside the component metadata.<br>'templateUrl' points to an external HTML file that contains the component's template.
Click to reveal answer
beginner
Why is metadata important in Angular components?
Metadata tells Angular how to create and display the component, what HTML tag to use, what template and styles to apply, and how to connect the component to the app.
Click to reveal answer
Which decorator is used to define an Angular component?
A@Component
B@Injectable
C@Directive
D@NgModule
What does the 'selector' property in @Component metadata specify?
AThe CSS styles for the component
BThe external JavaScript file for the component
CThe HTML tag name to use the component
DThe component's class name
Which property would you use to link an external HTML file as the component's template?
AstyleUrls
BtemplateUrl
Ctemplate
Dstyles
Can you use inline CSS styles inside the @Component decorator metadata?
AYes, using the 'styles' property
BOnly with the 'template' property
CNo, styles must be in external files
DOnly in the main app module
What happens if you forget to add a selector in the @Component metadata?
AThe component will throw a runtime error
BAngular will use a default selector
CThe component will automatically render everywhere
DThe component cannot be used in HTML templates
Explain the role of the @Component decorator and its metadata in Angular.
Think about how Angular knows what a component is and how to display it.
You got /5 concepts.
    Describe the difference between 'template' and 'templateUrl' in component metadata and when you might use each.
    Consider how you organize your HTML code for components.
    You got /4 concepts.