I'mVSPA
I'mVSPA

Reputation: 118

what is the difference between annotations and decorators in angular2

@Component({
  selector: 'app',
  template: 'Hello World!'
})
class MyComponent {}

what are the differences between annotations and decorators in angular2/4? how we can use the annotations and why? when we use decorators and why? what is tha image annotation Example: how i can do tag annotation for apicture in angular2/4 if any one have example please share it to me

Thank you in advance

Upvotes: 3

Views: 7198

Answers (1)

CandleCoder
CandleCoder

Reputation: 1503

Decorators are a proposed standard for ECMAScript 2016 by Yehuda Katz, to annotate and modify classes and properties at design time. This sounds pretty much like what annotations do right? Well… sort of. Let’s take a look at what a decorator looks like:

// A simple decorator
@decoratorExpression
class MyClass { }

@Component is an annotation that tells Angular, that the class, which the annotation is attached to, is a component.

@Component is something we need to import from the Angular framework like this:

import { 
  ComponentMetadata as Component,
} from '@angular/core';

For more you can look into this Difference.

Upvotes: 4

Related Questions