-
Solution to original over-simplified problem
:
<div *ngIf="hasBeenShown" style="width: 100%;" [hidden]="!grid2Showing">
<ag-grid-angular #agGrid2 style="width: 100%; height: 200px;" class="ag-theme-fresh" [gridOptions]="gridOptions">
</ag-grid-angular>
</div>
-
实际问题的解决方案:ag grid在投影内容(ng内容)时击中gridReady,在这种情况下,在嵌套的tab组件中:
(一)(
Solution from @antirealm
)在嵌套的tab组件上创建一个公共的hasbeenacactive变量,然后在ag网格上的*ngIf direct中使用它:
export class NestedTabComponent ... {
...
public hasBeenActive: boolean = false;
activate() {
this.active = true;
this.hasBeenActive = true;
}
....
<nested-tab title="Second grid" #myTab>
<div style="width: 100%;">
<ag-grid-angular *ngIf="myTab.hasBeenActive"
...>
</ag-grid-angular>
</div>
</nested-tab>
b)修改嵌套选项卡组件
to use a template
如果存在,则将任何嵌套选项卡的内容包装在模板中不应立即初始化的内容:
@Component({
selector: 'nested-tab',
template: `
<div *ngIf="hasBeenActive" [hidden]="!active">
<ng-container *ngTemplateOutlet="content"></ng-container>
<ng-content></ng-content>
</div>`
})
export class NestedTabComponent implements OnInit {
@ContentChild(TemplateRef) content;
....
<nested-tab title="Second grid">
<ng-template>
<p>The Second grid rendered:</p>
<div style="width: 100%;">
<ag-grid-angular ...></ag-grid-angular>
</div>
</ng-template>
</nested-tab>