One of the nice underused features of Angular is the support for decorators (through Typescript).
From the Typescript documentation:
A Decorator is a special kind of declaration that can be attached to a class declaration, method, accessor, property, or parameter. Decorators use the form
@expression
, whereexpression
must evaluate to a function that will be called at runtime with information about the decorated declaration.
A nice example of the usage of decorators is the ngx-auto-unsubscribe library. This Class decorator that will automatically unsubscribe from observable subscriptions when the component is destroyed.
An example: