
Learning Angular
By :

Decorators allow us to add metadata to class declarations for further use. By creating decorators, we define special annotations that may impact how our classes, methods, or functions behave or alter the data we define in fields or parameters. They are a powerful way to augment our type's native functionalities without creating subclasses or inheriting from other types. It is, by far, one of the most exciting features of TypeScript. It is extensively used in Angular when designing components or managing dependency injection, as we will learn in Chapter 5, Managing Complex Tasks with Services.
You will probably not need to write a decorator, but knowing their rationale and how they work is helpful to work with Angular applications.
We can define up to four different types of decorators, depending on what element each type is meant to decorate:
Before discussing the preceding decorators, we must...