Sha*_*ore 7 typescript angular
在Udemy上做一门课程的时候,我们一直在允许组件使用@Input()组件类中的装饰器传递数据.
在通过ngBook-2阅读时,我发现input在@Component装饰器中使用该属性还有另一种方法.
关于SO的这个类似的问题,一个人回答说:
使用输入的一个优点是类的用户只需要查看传递给@Component装饰器的配置对象以查找输入(和输出)属性.
并查看文档说明:
无论您使用输入/输出还是@ Input/@输出,结果都是相同的,因此选择使用哪一个主要是一种风格决定.
实际上,最有用的信息主要是相互矛盾的,具体取决于你的外观.
在@Component里面
@Component({
selector: 'product-image',
inputs: ['product'],
template: `
<img class="product-image" [src]="product.imageUrl">
})
class ProductImage {
product: Product;
}
Run Code Online (Sandbox Code Playgroud)
内部课程
@Component({
selector: 'product-image',
template: `
<img class="product-image" [src]="product.imageUrl">
})
class ProductImage {
@Input() product: Product;
}
Run Code Online (Sandbox Code Playgroud)
我想知道的事情
根据官方的Angular 2风格指南,STYLE 05-12说
不要使用
@Input和@Output替代的输入和输出性能@Directive和@Component装饰
好处是(来自指南):
@Input或者@Output,您可以修改一个地方.我个人使用这种风格,非常感谢它帮助保持代码干.
| 归档时间: |
|
| 查看次数: |
10647 次 |
| 最近记录: |