What is the difference between annotation and decorator?
Annotation and decorator both have symbol @ but still, they have some different language features-
Annotation | Decorator | |
---|---|---|
1. | These are metadata set on the class using the Reflect Metadata Library. | Decorator correlates to a function that is called on the class. |
2. | It is used by the Traceur compiler. | It is used by the Typescript compiler. |
3. | Annotations are hardcoded. | Decorators are not hardcoded. |
4. | Annotation Imports: import {ComponentAnnotation as Component} from ‘@angular/core’; | Decorator Imports: import {Component} from ‘@angular/core’; |
BY Best Interview Question ON 22 Sep 2021