While doing a course on Udemy we have been allowing components to be passed data dy using the @Input()
decorator in the component class.
While reading through ngBook-2 I have found that there is another approach by using the input
property inside an @Component
decorator.
THIS similar question on SO, One person answered:
One advantage of using inputs is that users of the class only need to look at the configuration object passed to the @Component decorator to find the input (and output) properties.
and look through documentation state that:
Whether you use inputs/outputs or @Input/@Output the result is the same so choosing which one to use is largely a stylistic decision.
Really, the most useful information about this is mostly conflicting depending on where you look.
Inside @Component
@Component({
selector: 'product-image',
inputs: ['product'],
template: `
<img class="product-image" [src]="product.imageUrl">
})
class ProductImage {
product: Product;
}
Inside Class
@Component({
selector: 'product-image',
template: `
<img class="product-image" [src]="product.imageUrl">
})
class ProductImage {
@Input() product: Product;
}
Things I would like to know
- What one would be more of "best practice" usage?
- When would you use one over the other?
- Are there any differences at all?