Tej*_*hta 6 parent-child angular-material angular mat-expansion-panel
我有 2 个不同的组件,我在其中使用 Angular - Expansion Panel 进行可扩展的摘要视图。
我能够<mat-expansion-panel>成功集成到单个组件。
我需要帮助,使Component2.html作为母公司Component1.html(中expand-展开请参见下图)
组件 1 应该能够独立展开和折叠以显示数据
组件 2 应该将组件 1 嵌入到自身中,所以当 Component 1 is expanded it can show its data and display remaining Child components
注意- 组件都具有兄弟关系,no parent child或child - parent
组件1.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>
Run Code Online (Sandbox Code Playgroud)
组件2.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>
Run Code Online (Sandbox Code Playgroud)
.ts 文件
panelOpenState = true;
Run Code Online (Sandbox Code Playgroud)
更新
罗比在下面给出的答案适用于parent - child component relation 但不适用于sibling component
一种方法是使用共享服务 - https://angular.io/guide/component-interaction#parent-and-children-communicate-via-a-service
然而,我发现以下解决方案更简单,它允许在两个兄弟姐妹之间共享数据。
应用程序-sibling2.component.ts
import { AppSibling1Component } from '../app-sibling1/app-sibling1.component';
export class AppSibling2Component {
@Input() data: AppSibling1Component;
...
}
Run Code Online (Sandbox Code Playgroud)
在您的父组件模板中:
<!-- Assigns "AppSibling1Component" instance to variable "data" -->
<app-sibling1 #data></app-sibling1>
<!-- Passes the variable "data" to AppSibling2Component instance -->
<app-sibling2 [data]="data"></app-sibling2>
Run Code Online (Sandbox Code Playgroud)
我相信这就是您正在寻找的。如果您有任何疑问,请告诉我
| 归档时间: |
|
| 查看次数: |
282 次 |
| 最近记录: |