2017-10-21 110 views
0

我有分量與已經裝在一個HTML頁面代碼Angular 2/4:如何在彈出窗口中使用現有的組件實例?

analytics.html

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

我在同一頁面analytics.html彈出對話框選擇「測試-COMP」,其中我想顯示相同的實例(#refcomp),而不是再次加載它(test-comp)。

-Currently我再次創造一個更實例

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

我怎麼能這樣做?

+0

你可以有點解釋清楚你的問題 –

回答

1

其實,我們必須渲染它兩次。 但爲了滿足您的要求,我們可以使用一個小小的黑客。

將test-comp放入模板/ ng-template標籤中。

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

使用它,無論你想顯示(在主頁上和型號彈出),使用下面的代碼

<div *ngIf="false; else myTemplate"></div> 
相關問題