【发布时间】:2021-07-28 08:13:37
【问题描述】:
我尝试将数据传递给 msg 组件以过滤组件,并且两个组件都注入到主组件中,我尝试了几种组合但仍然无法做到。
我不知道@input 或@output 用什么?
main.component.html
<app-msg></app-msg> // pass data from this component to fitler component
<app-filter (filterMSg)='msg'></app-filter>
filter.component.ts
filterMSg:string = '';
msg.component.ts
msg:string = 'text from msg component';
【问题讨论】:
-
@Input和@Output用于在另一个选择器中使用一个选择器的相关组件。例如。在您的情况下,您可以将其用于数据共享 b/n Main 组件以及 Msg 或 Filter 组件。对于不相关的组件,您可以查看单例服务。见here。
标签: angular typescript