【发布时间】:2017-05-31 09:16:02
【问题描述】:
我的目标是将字符串参数传递给组件。示例:我有一个包含并显示标题和副标题的组件。我想在设置选择器时传递该字符串。比如:
@Component({
selector: 'title-subtitle',
})
在 html 中:
<title-subtitle title="My title" subtitle="My subtitle"></title-subtitle>
【问题讨论】:
-
查看此实时 plnk。它可以帮助你plnkr.co/edit/LEtEN9?p=preview
-
这正是我的答案:p。具体来说,您不能只传递您想要的字符串参数。您可以使用来自 Angular2 的父子通信,它使用
@Input,您可以在其中发送带有其属性的Object。
标签: angular typescript components