我有一个树视图组件(它使用树视图项目组件),我想让用户定义项目的模板。
如下所示(它将显示"Item:“,后跟粗体名称):
<tree-view
[children]="folders"
childrenProperty="children">
<template>Item:<b>{{item.name}}</b></template>
</tree-view>我可以在TreeView组件类中使用@ContentChild检索TemplateRef,并从TreeViewItem组件访问它,但是我还没有找到如何将它注入到项的dom中。
你可以在我的树形视图组件上找到一个柱塞:http://plnkr.co/edit/IMqKV4TrwHoiWfJKHHQn?p=preview
有没有办法使用Angular 2来实现这一点?
发布于 2016-02-25 21:07:47
经过大量的挖掘,我发现没有任何方法可以达到我想要的效果。
一种解决方法是为树的每个项目加载(使用DynamicComponentLoader)给定的组件(在输入中)。
<tree-view
[children]="folders"
childrenProperty="children"
[itemComponentClass]="itemComponent">
</tree-view>其中itemComponent是对组件(具有模板)的类的引用。
不是更好的方法,但它是有效的:http://plnkr.co/edit/96IWGkw3owtUWfuG299V?p=preview
https://stackoverflow.com/questions/35445300
复制相似问题