While reading about @Input()
and @Output()
I have found that we can use an alias instead of using the property name for the decorators.
Example
class ProductImage {
//Aliased
@Input('myProduct') product: string;
//Un-aliased
@Input() product: string;//not aliased
}
HTML
//Aliased attribute
<SomeComponent [myProduct] = "Product Name"></SomeComponent>
//Un-aliased attribute
<SomeComponent [product] = "Product Name"></SomeComponent>
The official Angular documentation says:
Sometimes we want the public name of an input/output property to be different from the internal name. This is frequently the case with attribute directives. Directive consumers expect to bind to the name of the directive. For example, when we apply a directive with a myClick selector to a tag, we expect to bind to an event property that is also called myClick.
And This tutorial briefly explains it:
an alias let's me override the property name to be the alias instead of the original property name
Other than that I have not been able to find anything else on aliasing @Input()
and @Output()
on SO or through Google.
Things I would like to know are:
- What does 'aliasing' attempt to achieve?
- Is 'aliasing' something that we should be using regularly?