【发布时间】:2019-06-12 13:29:42
【问题描述】:
我必须在同一个组件中多次显示带有Clarity's stack-view 的键值对。
为避免代码重复,我想使用ng-template 和ngTemplateOutlet。
不幸的是,外部的clr-stack-block 只有在除了ngTemplateOutlet 之外还包含一个具有静态内容的附加clr-stack-block 元素时才能扩展。
请看这里:https://stackblitz.com/edit/clarity-angular-7-2ue7wd
app.component.html 包含我的示例代码,并展示了外部 clr-stack-block 只有在包含额外的静态元素时才能展开。
<ng-template #propertyList let-obj="obj" let-props="props">
<clr-stack-block *ngFor="let prop of props">
<clr-stack-label>{{prop}}</clr-stack-label>
<clr-stack-content>{{ !obj[prop] ? '-' : obj[prop] }}</clr-stack-content>
</clr-stack-block>
</ng-template>
<clr-stack-view>
<clr-stack-block [clrSbExpanded]="true">
<clr-stack-label>not expandable - but why?</clr-stack-label>
<!-- don't use a 'ng-container' here as it will break the stack view -->
<clr-stack-block
*ngTemplateOutlet="propertyList; context: {obj: {name: 'John Doe', birthdate: '01. Jan 1970'}, props: ['name', 'birthdate']}">
</clr-stack-block>
</clr-stack-block>
<clr-stack-block [clrSbExpanded]="true">
<clr-stack-label>expandable - because of additional static block element?</clr-stack-label>
<clr-stack-block
*ngTemplateOutlet="propertyList; context: {obj: {name: 'Test User', birthdate: '10. Feb 2000'}, props: ['name', 'birthdate']}">
</clr-stack-block>
<clr-stack-block>
<clr-stack-label><i>static</i></clr-stack-label>
<clr-stack-content><i>clr-stack-block</i></clr-stack-content>
</clr-stack-block>
</clr-stack-block>
</clr-stack-view>
我无法弄清楚我在这里缺少什么。
感谢您的建议!
【问题讨论】: