简体   繁体   English

角2/4:如何在弹出窗口中使用现有组件实例?

[英]Angular 2/4 :How to use the existing component instance in a popup?

I have component with selector 'test-comp' which is already loaded in a html page with code 我有带有选择器'test-comp'的组件,该选择器已经在带有代码的html页面中加载

analytics.html analytics.html

<test-comp #refcomp ></test-comp>

I have a popup dialog in the same analytics.html page in which I would like show the same instance(#refcomp) instead of loading it(test-comp) again. 我在同一analytics.html页面中有一个弹出对话框,在其中我想显示相同的实例(#refcomp)而不是再次加载它(test-comp)。

-Currently I'm again creating one more instance -目前,我再次创建了一个实例

<test-comp #popup ></test-comp>

How can I do that? 我怎样才能做到这一点?

Actually, we have to render it twice. 实际上,我们必须渲染两次。 But to fulfill your requirement, we can use a small hack. 但是为了满足您的要求,我们可以使用小型技巧。

Place test-comp inside a template/ng-template tag. 将test-comp放在template / ng-template标记内。

<template  #myTemplate>
        <test-comp #refcomp ></test-comp>
 </template>

use it wherever you want to display (on the main page and on model pop-up), using below code 使用以下代码在您想要显示的位置(在主页和模型弹出窗口上)使用它

<div *ngIf="false; else myTemplate"></div>

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

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