[英]Angular 2 show same component with same data in other component
Its more design question. 它更多的设计问题。
As an example I have a page that display the data, and I have a button that opens up the modal. 例如,我有一个显示数据的页面,还有一个打开模式的按钮。 Need to show exact same page inside the modal, and this modal is an external component.
需要在模式内部显示完全相同的页面,并且该模式是外部组件。
More detail: I have a main component, inside which I have another component that receives some data from it via @Input decorator. 详细信息:我有一个主要组件,在里面有另一个组件,该组件通过@Input装饰器从中接收一些数据。 When I view the page "main-component" it shows all data as expected from message-preview.
当我查看页面“主要组件”时,它显示了所有来自消息预览的数据。 However I created a separate modal component which is child message-preview component, which is triggered through the button inside .
但是,我创建了一个单独的模态组件,它是子消息预览组件,它是通过中的按钮触发的。 Ho
何
How can I duplicate (clone) exact same page as in in modal component without passing data again as its already there? 如何复制(克隆)与模态组件中的页面完全相同的页面,而又不传递数据,因为它已经在那里?
<main-component>
<app-message-preview [message]="selectedItem" [context]="context">
</app-message-preview>
</main-component>
External componenet 外部组件
<modal-component>
<app-message-preview [message]="selectedItem" [context]="context">
</app-message-preview>
</modal-component>
You can use a BehaviorSubject to comunicate between services. 您可以使用BehaviorSubject在服务之间进行通信。 Please check these links: http://jasonwatmore.com/post/2016/12/01/angular-2-communicating-between-components-with-observable-subject
请检查以下链接: http : //jasonwatmore.com/post/2016/12/01/angular-2-communication-between-components-with-observable-subject
https://medium.com/dailyjs/3-ways-to-communicate-between-angular-components-a1e3f3304ecb https://medium.com/dailyjs/3-ways-to-communicate-between-angular-components-a1e3f3304ecb
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.