简体   繁体   English

在输入角度2处传递更多数据

[英]Passing more data @input angular 2

How can we switch more than one component to another component? 我们如何将多个组件切换到另一组件? I need to use the "two way data binding". 我需要使用“双向数据绑定”。

I tried the following way: 我尝试了以下方法:

<app-drawer-menu [popup]="getPopupInstance" [appHeader]="getAppHeaderInstance"></app-drawer-menu>


 export class DrawerMenuComponent implements OnInit {


    @Input() private popup: DialogLoginSignupComponent;
    @Input() private appHeader: AppHeaderComponent;

    ....

I need to go to the "DrawerMenuComponent" component "DialogLoginSignupComponent" and "AppHeaderComponent" 我需要转到“ DrawerMenuComponent”组件“ DialogLoginSignupComponent”和“ AppHeaderComponent”

this does not work. 这行不通。 Where am I wrong? 我哪里错了?

thx! 谢谢!

If you want to do so, You'll have to use a Service and pass the component class name to use to your child component. 如果要这样做,则必须使用服务并将要使用的组件类名称传递给子组件。 Then, use the ComponentFactoryResolver to create the component like this : 然后,使用ComponentFactoryResolver创建如下组件:

let factory = this.cfr.resolveComponentFactory(MyComponent);
this.cmp = this.modalBody.createComponent(factory);

If you want more details, please looks the file modal.component.ts here : Github link 如果您需要更多详细信息,请在此处查看文件modal.component.ts: Github链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM