What is the difference between annotation and decorator?

I am confused when to use terminological annotation and when to use a decorator?

@Component({ selector: 'tabs', template: ` ` }) export class Tabs { } 
+6
source share
3 answers

The decorator corresponds to the function called in the class, while annotations are the "only" metadata defined in the class using the Reflect metadata library.

With TypeScript and ES7, @Something is a decorator. In the context of Angular2, decorators such as @Component , @Injectable , ... define metadata for a decorated element using the Reflect.defineMetadata method.

This question may interest you to find out what the decorator is actually:

+7
source

Tracer gives us annotations . TypeScript gives us decorators . But Angular 2 supports both.

Annotations create an array of annotations. while Decorators are functions that receive a decorated object and can make any changes to it.

Like Angular, use TypeScript instead of atScript to use decorators. Basically there are four kinds of decorators do

  • Class decorators, for example. @Component and @NgModule
  • Property decorators for properties within classes, for example. @Input and @Output
  • Method decorators for methods inside classes, for example. @HostListener
  • Parameter decorators for parameters inside class constructors, for example. @Inject

For more information, you can contact

0
source

Angular annotations are used to create an array of annotations. This is just a collection of class metadata using the Reflect metadata library.

Decorators in Angular are design patterns used to separate decorating or modifying a class without changing the source code.

0
source

All Articles