【发布时间】:2017-12-14 19:04:00
【问题描述】:
我正在思考这个问题,找不到任何解释。
在Angular2中向组件传递参数时
给定
<my-component [attr]="someModelVariable"></my-component>
似乎有两种接受attr绑定值的方式:
@Component{(
selector: "my-component",
inputs: ["attr"]
)}
export class MyComponent {
}
或者你这样做:
@Component{(
selector: "my-component"
)}
export class MyComponent {
@Input()
public attr: any;
}
实际上我已经看到同时使用两者的代码,有人可以解释它们之间的区别是什么吗?
/里卡德
【问题讨论】:
-
没有区别,
@Component()是规范的地方。还要记住,有些用户使用纯 ES5(不使用 TypeScript)编写代码,因此他们需要一种无需装饰器的方式。
标签: angular