I am working on an application in which I am using Angular 11 and Angular material. In this application I have implemented angular material accordion which gets generated dynamically. And in the accordion title I have also implemented a dropdown menu.
Problem: The problem is when I click on dropdown it gets opened but accordion is also getting opened/closed which is technically incorrect. As you can see below in images; by default accordion will be opened but when I click on dropdown menu it gets closed which is wrong as I didn't click on Accordion icon.
Below are the code files for better understanding.
app.component.html
<div class="trendFlow">
<mat-accordion class="example-headers-align" *ngFor="let accordionData of accordianArray" multi>
<mat-expansion-panel [expanded]="currentSensorId==accordionData.sensorId">
<mat-expansion-panel-header>
<mat-panel-title>
{{accordionData.sensorName|translate}}
</mat-panel-title>
<!-- SAMPLE CODE STARTS -->
<div class="dropMenu">
<mat-form-field appearance="fill">
<mat-label>{{currentTimeValue|translate}}</mat-label>
<mat-select [(ngModel)]="currentTimeValue">
<mat-option *ngFor='let property of timeProperties'
(click)="handleTimeSelection(property.name)">
{{property.name|translate}}
</mat-option>
</mat-select>
</mat-form-field>
</div>
<!-- SAMPLE CODE ENDS -->
</div>
app.component.ts
accordianArray: any = [];
currentSensorId: number = 0;
public currentTimeValue = '1 Day';
timeProperties: any = [
{ name: '1 Hour', id: 1 },
{ name: '4 Hours', id: 1 },
{ name: '1 Day', id: 1 }
];
handleTimeSelection(propertyName: string) {
this.currentTimeValue = propertyName;
}
any solution please ?