【发布时间】:2018-10-31 18:52:23
【问题描述】:
我正在使用 Clarity 的数据网格,并希望构建更小的组件以遵循此结构:
- 网格
- 标题
- 项目
- 页脚
这是我的网格组件模板:
<clr-datagrid>
<app-grid-header></app-grid-header>
<app-grid-item *ngFor="let city of cities$ | async" [city]="city"></app-grid-item>
<clr-dg-footer>{{(cities$ | async).length}} cities</clr-dg-footer>
</clr-datagrid>
这是我的网格标题:
import { Component } from '@angular/core';
@Component({
selector: 'app-grid-header',
template: `
<clr-dg-column>City</clr-dg-column>
<clr-dg-column>Capital</clr-dg-column>
<clr-dg-column>Population</clr-dg-column>
<clr-dg-column>Country</clr-dg-column>
`
})
export class GridHeaderComponent {}
这是我的网格项目:
import { Component, Input } from '@angular/core';
import { City } from '../city.model';
@Component({
selector: 'app-grid-item',
template: `
<clr-dg-row>
<clr-dg-cell>{{city.name}}</clr-dg-cell>
<clr-dg-cell>{{city.capital}}</clr-dg-cell>
<clr-dg-cell>{{city.population}}</clr-dg-cell>
<clr-dg-cell>{{city.country.name}}</clr-dg-cell>
</clr-dg-row>
`
})
export class GridItemComponent {
@Input()
city: City;
}
如果我摆脱了专用的哑组件并内联所有内容,网格看起来就像预期的那样:
<clr-datagrid>
<clr-dg-column>City</clr-dg-column>
<clr-dg-column>Capital</clr-dg-column>
<clr-dg-column>Population</clr-dg-column>
<clr-dg-column>Country</clr-dg-column>
<clr-dg-row *ngFor="let city of cities$ | async">
<clr-dg-cell>{{city.name}}</clr-dg-cell>
<clr-dg-cell>{{city.capital}}</clr-dg-cell>
<clr-dg-cell>{{city.population}}</clr-dg-cell>
<clr-dg-cell>{{city.country.name}}</clr-dg-cell>
</clr-dg-row>
<clr-dg-footer>{{(cities$ | async).length}} cities</clr-dg-footer>
</clr-datagrid>
我找不到任何解决此类问题的方法。
我尝试将app-grid-header 模板更改为[app-grid-header] 并将其用作指令<div app-grid-header></div>,但这并没有解决问题。
我还尝试将encapsulation 更改为其他可能的选项,但都没有产生影响。
为了使这项工作按预期进行,我必须进行哪些更改?
【问题讨论】: