It's ok.
It's ok.

Reputation: 53

What are the differences between the @Input and @HostBinding decorators in Angular?

These decorators looks like they are doing the same thing.

If I create a Directive, the Input and HostBinding decorators are receiving a value of a specific attribute from the template.

What are exatly the differencies between these decorators in Angular ?

Thanks guys.

EDIT:

@Segev gives an incorrect answer. According to Angular official documentation :

Input - Decorator that marks a class field as an input property and supplies configuration metadata. The input property is bound to a DOM property in the template. During change detection, Angular automatically updates the data property with the DOM property's value.

HostBinding - Decorator that marks a DOM property as a host-binding property and supplies configuration metadata. Angular automatically checks host property bindings during change detection, and if a binding changes it updates the host element of the directive.

As i can read in the Angular official documentation these decorators are similar and I don't understand the Segev answer....

Upvotes: 0

Views: 391

Answers (1)

Segev -CJ- Shmueli
Segev -CJ- Shmueli

Reputation: 1621

Two completely different things

@Input() - allows you to "inject" context into a component

@HostBinding() - let you access the element encapsulating (or "hosting") your component

Upvotes: 1

Related Questions