dmx
dmx

Reputation: 1990

Angular 6 decorators - Can someone please demystify decorators ? How it works, In which case to use

I am learning angular 6. There is something I am trying to understand, but still cannot fully understand. It is decorator. Decorator can be use on classes, method, variable, ... I have read multiple articles about this topic. But still don't get all.

  1. What are there Decorators exactly ?
  2. When should I use them ?
  3. How to create Custom Decorator ?

Can you please explain it with simple world ? with examples.

Thanks in advance

Upvotes: 1

Views: 99

Answers (2)

Auqib Rather
Auqib Rather

Reputation: 396

Decorators are actually just functions, it’s as simple as that, and are called with whatever they are decorating. A method decorator will be called with the value of the method it’s decorating, and a class decorator will be called with the class to be decorated.Here is an example of custom decorator.

function Console(target) {
console.log(target);
}

@Console("hey")
class ExampleClass {
constructor() {
console.log('Yo!');
 }
}

to know more About Decorators I Found https://toddmotto.com/angular-decorators as best resource

Upvotes: 2

mruanova
mruanova

Reputation: 7105

Input is for passing an object from parent to child.

Ouput is for raising an event from child to parent.

https://www.sitepoint.com/angular-2-components-inputs-outputs/

Upvotes: 0

Related Questions