【发布时间】:2019-04-06 04:48:16
【问题描述】:
<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>
刚开始使用 Angular Material 并遇到了 mat-expansion-panel 的问题。我的面板在展开时会出现一系列 mat-form-field 元素。
我有几个获取数据的点击事件; (点击)="getPrimaryAddress() 其余的只是在选择 X 按钮后清除数据,例如 (click)="streetOneValue=''"
但是,当我单击 X 按钮以清除特定值时,getPrimaryAddress() 事件会再次触发并重新填充元素中的数据。每当我选择其他点击事件时,是否有任何方法阻止 getPrimaryAddress() 函数触发?
我需要延迟加载数据,这就是为什么我在点击事件而不是 OnInit 中处理它的原因
【问题讨论】:
标签: html angular angular-material2