【发布时间】:2023-03-10 21:22:01
【问题描述】:
我有 2 个不同的组件,我在其中使用 Angular - 扩展面板来扩展摘要视图。
我能够成功地将<mat-expansion-panel> 集成到各个组件中。
我需要帮助以使 Component2.html 成为 Component1.html 的父级(在扩展内展开 - 请参见下图)
-
组件 1 应该能够独立展开和折叠以显示数据
-
组件 2 应该在自身内嵌入组件 1,所以当
Component 1 is expanded it can show its data and display remaining Child components
注意 - 两个组件都有兄弟关系,no parent child 或child - parent
Component1.html
<div class="row">
<div class>
<dl class="row property_set" data-property-set-name="data">
<mat-accordion>
<mat-expansion-panel (opened)="doExpand = true"
(closed)="doExpand = false">
<mat-expansion-panel-header>
<mat-panel-title>
<dt class="col-sm-4 record_property">data</dt>
</mat-panel-title>
<mat-panel-description>
<dd class="col-sm-8 record_property_value data_name" id="{{genId(data.name)}}">
<inline-misal-edit
[(field)]="data.name" [elementType]="a.bName" (fieldChange)="dataModified(data)"
cols="30" rows="1"></inline-misal-edit>
</dd>
</mat-panel-description>
</mat-expansion-panel-header>
<dt class="col-sm-4 record_property">news</dt>
<dd class="col-sm-8 record_property_value">{{data.news?.created | news}}</dd>
</mat-expansion-panel>
</mat-accordion>
</dl>
</div>
Component2.html
<dl class="row property_set" data-property-set-name="misal">
<mat-accordion>
<mat-expansion-panel (opened)="doExpand = true"
(closed)="doExpand = false">
<mat-expansion-panel-header>
<mat-panel-title>
misal Id
</mat-panel-title>
<mat-panel-description>
<dd class="col-sm-10 record_property_value" data-property-type="select">{{misal.id || 'new'}}</dd>
</mat-panel-description>
</mat-expansion-panel-header>
<dd class="col-sm-10 record_property_value misal_name">{{misal.data[0].name}}</dd>
<dt class="col-sm-2 record_property">Country Pass</dt>
<dt class="col-sm-2 record_property">Plugins Program</dt>
<dd class="col-sm-10 record_property_value">
<north-dhamma[(misal)]="misal" [editMode]="editMode" (misalChange)="recordModified.emit()"></registry-number>
</dd>
<dt *ngIf="misal.value === 'hovered'" class="col-sm-2 record_property">Related Plugins Program</dt>
<dd *ngIf="misal.value === 'hovered'" class="col-sm-10 record_property_value">
<land-hole></land-hole>
</dd>
</mat-expansion-panel>
</mat-accordion>
</dl>
.ts 文件
panelOpenState = true;
更新
Robbie 下面给出的答案适用于parent - child component relation ,但不适用于sibling component
【问题讨论】:
-
@Eldho 这就是我要找的东西 - stackblitz.com/edit/…。这适用于
parent to child component。在我的情况下both components are silbings我正在寻找适用于我的场景的解决方案
标签: angular angular-material parent-child mat-expansion-panel