I am confused when to use term annotation and when to use decorator ?
@Component({
selector: 'tabs',
template: `
`
})
export class Tabs {
}
Annotations are used to create annotations attribute to store the array and pass the metadata to the constructor of the annotated class. Annotations are hard-coded and are used by the Traceur compiler.
Decorators are a design pattern that is used to separate modification or decoration of a class without modifying the original source code. In AngularJS, decorators are functions that allow a service, directive or filter to be modified prior to its usage.
The rows or tuples are the data, and the columns would be the metadata; they define what each value is for any given row. Annotations are code snippits you put in at the java class or method level that further define data about the given code, but without changing any of the actual coded logic.
Java annotations are metadata (data about data) for our program source code. They provide additional information about the program to the compiler but are not part of the program itself. These annotations do not affect the execution of the compiled program. Annotations start with @ .
A decorator corresponds to a function that is called on the class whereas annotations are "only" metadata set on the class using the Reflect Metadata library.
With TypeScript and ES7, @Something
is a decorator. In the context of Angular2, decorators like @Component
, @Injectable
, ... define metadata for the decorated element using the Reflect.defineMetadata
method.
This question could interest you to find out what a decorator actually is:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With