0
0
Angularframework~5 mins

Standalone component declaration in Angular - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a standalone component in Angular?
A standalone component is an Angular component that does not require being declared inside an NgModule. It can be used independently and imported directly where needed.
Click to reveal answer
beginner
How do you declare a component as standalone in Angular?
You add the property standalone: true in the @Component decorator metadata.
Click to reveal answer
intermediate
Can standalone components import other standalone components or Angular modules?
Yes, standalone components can import other standalone components, directives, pipes, or Angular modules using the <code>imports</code> array in the <code>@Component</code> decorator.
Click to reveal answer
intermediate
What is the benefit of using standalone components in Angular?
Standalone components simplify Angular apps by reducing the need for NgModules, making the code easier to read, maintain, and enabling faster compilation.
Click to reveal answer
beginner
Show a simple example of a standalone component declaration in Angular.
Example:<br><pre>import { Component } from '@angular/core';

@Component({
  selector: 'app-hello',
  standalone: true,
  template: `<h1>Hello, Angular!</h1>`
})
export class HelloComponent {}</pre>
Click to reveal answer
What property must be set to true to make an Angular component standalone?
Astandalone
Bindependent
CmoduleFree
DselfContained
Can a standalone component be used without declaring it in an NgModule?
ANo, it must be declared in an NgModule.
BOnly if it imports an NgModule.
CYes, it can be used directly.
DOnly in Angular versions before 14.
Where do you specify other components or modules a standalone component uses?
AIn the bootstrap array inside NgModule.
BIn the declarations array inside NgModule.
CIn the providers array inside the component.
DIn the imports array inside the @Component decorator.
Which Angular version introduced standalone components?
AAngular 12
BAngular 14
CAngular 10
DAngular 16
What is a key advantage of standalone components?
AThey reduce the need for NgModules.
BThey require more boilerplate code.
CThey cannot import other components.
DThey only work with class components.
Explain how to create a standalone component in Angular and why it might be useful.
Think about how Angular components usually need NgModules and how standalone changes that.
You got /4 concepts.
    Describe how standalone components handle dependencies like other components or Angular modules.
    Consider where you specify what a component needs to work.
    You got /3 concepts.