【发布时间】:2020-04-05 01:54:15
【问题描述】:
我最近在我的 Angular 项目中添加了 Angular Material 手风琴组件。在 API 中,他们使用为自动关闭面板提供的示例:https://material.angular.io/components/expansion/examples (opened) = panelStateOpen 并在组件中指定布尔值)
我这样做了,但是因为我正在循环通过menuItems 的信息,有两个组件,然后注入我的扩展面板,panelOpenState 不正确。
现在,我有
<mat-accordion *ngFor="let menuItem of menuItems">
<confmenu menuItem={{menuItem}}></confmenu>
</mat-accordion>
在我的父模板和我的 confmenu(子模板)中:
<mat-expansion-panel (opened)="panelOpenState=true" (closed)="panelOpenState=false">
<mat-expansion-panel-header>
<mat-panel-title>
{{menuItem}}
</mat-panel-title>
<mat-panel-description>
{{menuDescription}}
</mat-panel-description>
</mat-expansion-panel-header>
<mat-form-field>
<mat-select (change)="selectConfig($event.value)">
<mat-option *ngFor="let option of menuOptions" [value]="option" (click)="selectConfig(option)">
{{option}}
</mat-option>
</mat-select>
</mat-form-field>
</mat-expansion-panel>
在我拥有的孩子的组件中
panelOpenState = false;
整个ts是
/** @title Basic menu */
@Component({
selector: 'confmenu',
templateUrl: './confmenu.component.html',
styleUrls: ['./confmenu.component.scss']
})
export class ConfigurationMenu implements OnInit, OnDestroy {
@Input() menuItem: string;
panelOpenState = false;
constructor() {}
ngOnInit() {
}
ngOnDestroy() {
//blank for now
}
selectConfig(value:string){
this.selectedConfig = value;
this._menuService.changeSelectedConfig(this.selectedConfig);
this._menuService.populateSelectedConfigConfigurations(this.selectedConfig);
}
}
关于如何使面板在单击另一个面板时关闭的任何想法?现在,它们都在单击另一个时保持打开状态。
【问题讨论】:
-
可以显示子组件的TS文件吗
-
@LALITKANTADIBYADARSHAN 我编辑了它
-
控制台是否出现错误
-
@LALITKANTADIBYADARSHAN,不,我不是。我不认为这是问题所在。我认为这是因为我有多个,它们在 for 循环中
标签: angular angular-material ngfor