<mat-expansion-panel (opened)="panelOpenState = true" (closed)="panelOpenState = false" (click)="getPrimaryAddress()">
<mat-expansion-panel-header>
<mat-panel-title>
Primay Address
</mat-panel-title>
<mat-panel-description>
{{panelOpenState ? 'Hide' : 'Display'}} Address
</mat-panel-description>
</mat-expansion-panel-header>
<div>
<mat-form-field class="example-form-field" style="margin-top: 20px;">
<input matInput type="text" placeholder="Street 1" [(ngModel)]="streetOneValue">
<button mat-button *ngIf="streetOneValue " matSuffix mat-icon-button aria-label="Clear" (click)="streetOneValue=''">
<mat-icon>close</mat-icon>
</button>
</mat-form-field>
<mat-form-field class="example-form-field" style="margin-top: 20px;">
<input matInput type="text" placeholder="Street 2" [(ngModel)]="streetTwoValue">
<button mat-button *ngIf="streetTwoValue " matSuffix mat-icon-button aria-label="Clear" (click)="streetTwoValue=''">
<mat-icon>close</mat-icon>
</button>
</mat-form-field>
</div>
<div>
<mat-form-field class="example-form-field" style="margin-top: 20px;">
<input matInput type="text" placeholder="Street 3" [(ngModel)]="streetThreeValue">
<button mat-button *ngIf="streetThreeValue " matSuffix mat-icon-button aria-label="Clear" (click)="streetThreeValue=''">
<mat-icon>close</mat-icon>
</button>
</mat-form-field>
<mat-form-field class="example-form-field" style="margin-top: 20px;">
<input matInput type="text" placeholder="Street 2" [(ngModel)]="countyValue">
<button mat-button *ngIf="countyValue " matSuffix mat-icon-button aria-label="Clear" (click)="countyValue=''">
<mat-icon>close</mat-icon>
</button>
</mat-form-field>
</div>
<div>
<mat-form-field class="example-form-field" style="margin-top: 20px;">
<input matInput type="text" placeholder="Post Code" [(ngModel)]="postcodeValue">
<button mat-button *ngIf="postcodeValue " matSuffix mat-icon-button aria-label="Clear" (click)="postcodeValue=''">
<mat-icon>close</mat-icon>
</button>
</mat-form-field>
<mat-form-field class="example-form-field" style="margin-top: 20px;">
<input matInput type="text" placeholder="Country" [(ngModel)]="primaryAddresscountryValue">
<button mat-button *ngIf="primaryAddresscountryValue " matSuffix mat-icon-button aria-label="Clear" (click)="primaryAddresscountryValue=''">
<mat-icon>close</mat-icon>
</button>
</mat-form-field>
</div>
</mat-expansion-panel>
Just started playing around with Angular Material and have run into an issue with the mat-expansion-panel. My panel hosts a series of mat-form-field elements at appear when expanded.
I have several click events one that gets the data; (click)="getPrimaryAddress() and the rest just clear the data once the X button is selected e.g (click)="streetOneValue=''"
However when I click the X button to clear a particular value the getPrimaryAddress() event fires again and just re-populates the data in the element. Is there anyway to stop the getPrimaryAddress() function from firing whenever I select the other click events?
I need the data to lazy load which is why I am handling it in a click event and not OnInit