以下片段與*ngComponentOutlet
一起使用來進行顯示。Angular 4 - * ngComponentOutlet澄清需要
我有以下工作代碼:
this.displayComponent({
'objects':[
{component: ToDisplayAComponent, expanded: false},
{component: ToDisplayBComponent, expanded: false}
]
})
對象值陣列將與*ngFor
被迭代然後並顯示我的組件。
我想要做的是不起作用以下(通過在同一個抽象組件的排列不同的情況下,被初始化具有不同屬性):
let compA = new ToDisplayAComponent(aProperty);
let compB = new ToDisplayAComponent(anotherPropert);
this.displayComponent({
'objects':[
{component: compA, expanded: false},
{component: compB, expanded: false}
]
});
除了解決方案對我的問題,這將是非常感激,我也很感興趣,會發生什麼,上面的代碼不起作用。
PS編譯,但引發此錯誤:
ERROR Error: No component factory found for [object Object]. Did you add it to @NgModule.entryComponents?
只是一個跟進的問題,當我在陣列中添加2次相同的組件是顯示兩次相同的實例? – Thodoris
@Thodoris,不,他們是不同的實例。這與您在模板中指定相同組件兩次幾乎相同 –
非常感謝。你的回答非常明確,寫得很好,但在批准之前,我想跟隨你所說的內容以及閱讀你的博客文章的文檔,因此可能需要幾天時間。 :) – Thodoris