What is a decorator in Angular? Name a few.
Model answer
A decorator is a function written with @ above a class, property or method that adds metadata or behaviour. Angular uses them to tell the framework what a class is. Examples: @Component marks a component, @Directive a directive, @Pipe a pipe, @Injectable a service, and @Input and @Output mark inputs and outputs in the classic style.
In newer Angular, signal-based functions such as input(), output() and viewChild() replace some property decorators, but the class decorators are still used.
Learn this topic
Angular Tutorial: Beginner to Advanced .
Sign in to add your own answer.
More questions
- What is Angular, and how is it different from AngularJS?
- What is a single-page application (SPA)?
- What does the Angular CLI do? Name some common commands.
- What is a standalone component, and why did Angular move away from NgModules?
- What is TypeScript, and why does Angular use it?
- Describe the structure of a basic Angular project.