I'm setting up a dynamic expansion panel in my Angular 7 application, I am showing a mat-expansion-panel by default in mat-accordion. Now I have an Add button, and I want if a user clicks on this button, a new mat-expansion-panel should append in mat-accordion with a small form or 4 form inputs.
I tried it with rendered2 class but it is not working for me. I might be missing something.
<mat-accordion id="quoteAccordion">
<mat-expansion-panel>
<mat-expansion-panel-header>
<mat-panel-title>
<!-- -->
Panel Title Here
<!-- -->
</mat-panel-title>
<mat-panel-description>
Panel description here
</mat-panel-description>
</mat-expansion-panel-header>
<!-- Panel Body -->
<div formArrayName="services" *ngFor="let service of services.controls; let i = index">
<mat-form-field appearance="outline" fxFlex="30" class="pr-4">
<mat-label> Description</mat-label>
<input matInput formControlName="title" required>
<mat-error>Description is required!</mat-error>
</mat-form-field>
</div
<!-- /Panel Body -->
</mat-expansion-panel>
<!--
on click of [Add] button
Need to append another expansion
panel with form input here
-->
</mat-accordion>
<!-- Ends Here -->
</div>
<button class="w-100" matTooltip="Add" type="button" mat-raised-button (click)="addAccordion()">
<mat-icon>add</mat-icon> ADD
</button>
I am expecting the output of adding dynamic mat-expansion-panel with expansion-header and the expansion-body contains a form-input.
Thanks in advance !!
*ngFordirective on<mat-expansion-panel>and set an array property on your component ts with your panels data, then simply push values to this array to have the new panels appended.