在通过ngBook-2阅读时,我发现在@Component装饰器中使用input属性还有另一种方法.
关于SO的THIS个类似的问题,一个人回答:
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.
并通过documentation状态看:
Whether you use inputs/outputs or @Input/@Output the result is the same so choosing which one to use is largely a stylistic decision.
实际上,最有用的信息主要是相互矛盾的,具体取决于你的外观.
在@Component里面
@Component({ selector: 'product-image',inputs: ['product'],template: ` <img class="product-image" [src]="product.imageUrl"> }) class ProductImage { product: Product; }
内部课程
@Component({ selector: 'product-image',template: ` <img class="product-image" [src]="product.imageUrl"> }) class ProductImage { @Input() product: Product; }
我想知道的事情
>更多的是“最佳实践”用法?
>你什么时候用一个而不是另一个?
>有什么不同吗?