在angular2組件中使用transclusion時,看起來我的'ViewChildren'無法檢測到這些組件。當我製作一個組件時,我直接定義了相同的組件,然後它可以正常工作。現在有人有辦法得到這個工作嗎?Angular2 ViewChildren與transclusion結合使用
1
A
回答
2
您可以使用@ContentChild()
或@ContentChildren()
查詢transcluded內容。
@ViewChild()
和'@ ViewChildren()`只允許查詢組件模板中的元素。
現在還angular 2/typescript : get hold of an element in the template
0
我試圖用我的錯誤消息組件做到這一點。其實你只需要用ContentChildren
修飾器代替ViewChildren
。它適用於ng內容元素。因此,您將獲得QueryList
,這是您的組件或元素的可迭代對象。
相關問題
- 1. Transclusion(真) - 結合值
- 2. 如何在Angular2中使用@ViewChildren?
- 3. 如何結合transclusion,replace和ngIf?
- 4. Angular2中的ViewChildren裝飾器可以使用接口嗎?
- 5. 如何在Angular2中測試transclusion(ng-content)?
- 6. 整合angular2與
- 7. 異步結合angular2
- 8. ViewChildren爲NG-模板
- 9. 嵌套指令與transclusion
- 10. Angular2與NodeJs合作
- 11. 角Transclusion
- 12. angular2 onError的圖像結合
- 13. Html.Raw()與Razor結合使用?
- 14. 與Monotouch結合使用PonyDebugger?
- 15. PHPExcel:結合使用「getHighestRow」與
- 16. 結合使用mime_content_type與ACF
- 17. Flot與Zepto結合使用
- 18. 結合使用str_replace與ut8_decode
- 19. ob_start()與wp_query結合使用
- 20. 使用Bridget.NET與Angular2
- 21. Angular2 @ViewChildren在其他組件中返回undefined
- 22. ViewChildren不ngFor
- 23. 使用holoeverywhere與actionBarSherlock結合使用
- 24. 使用ng-content與多個選擇器的Dart Angular 2 Transclusion
- 25. 如何整合Angular2與Java
- 26. 當與node.js服務器結合使用時,Angular2英雄示例雙倍POST
- 27. 如何在angularjs中使用transclusion?
- 28. Mediawiki Multilevel Transclusion
- 29. MediaWiki 1.16:Section transclusion
- 30. DI和transclusion
見僅供參考,我們使用術語*內容投影*而不是transclusion。 – drewmoore
感謝這個不錯的加法! –