0

我對Angular 2極其陌生,並且正在努力尋找方法來檢查我的md-input中的任何值是否已更改。Angular 2 - 檢查是否有任何默認值已更改

HTML

<md-card> 
    <h3>Contact details</h3> 
     <md-input-container class="containerRightMargin"> 
      <input mdInput placeholder="Telephone number" [disabled]="this.personalDetailsDisable" [(ngModel)]="accountService.client?.contact.telephoneNumber"> 
     </md-input-container> 
     <md-input-container> 
      <input mdInput placeholder="Email address" [disabled]="this.personalDetailsDisable" [(ngModel)]="accountService.client?.contact.email"> 
     </md-input-container> 
     <div> 
      <h3 class="headingWithButtonBeside">Address details</h3> 
      <button *ngIf="!this.personalDetailsDisable" class="floatingButtonBesideHeading" md-button color="accent" title="Click to find your new address using your new postcode.">Use postcode lookup</button> 
     </div> 
     <md-input-container class="containerRightMargin"> 
      <input mdInput placeholder="Flat name" [disabled]="this.personalDetailsDisable" [(ngModel)]="accountService.client?.address.flatName"> 
     </md-input-container> 
     <md-input-container> 
      <input mdInput placeholder="Flat number" [disabled]="this.personalDetailsDisable" [(ngModel)]="accountService.client?.address.flatNumber"> 
     </md-input-container> 
     <md-input-container class="containerRightMargin"> 
      <input mdInput placeholder="House name" [disabled]="this.personalDetailsDisable" [(ngModel)]="accountService.client?.address.houseName"> 
     </md-input-container> 
     <md-input-container> 
      <input mdInput placeholder="House number" [disabled]="this.personalDetailsDisable" [(ngModel)]="accountService.client?.address.houseNumber"> 
     </md-input-container> 
     <md-input-container class="containerRightMargin"> 
      <input mdInput placeholder="Street" [disabled]="this.personalDetailsDisable" [(ngModel)]="accountService.client?.address.street"> 
     </md-input-container> 
     <md-input-container> 
      <input mdInput placeholder="District" [disabled]="this.personalDetailsDisable" [(ngModel)]="accountService.client?.address.district"> 
     </md-input-container> 
     <md-input-container class="containerRightMargin"> 
      <input mdInput placeholder="City" [disabled]="this.personalDetailsDisable" [(ngModel)]="accountService.client?.address.city"> 
     </md-input-container> 
     <md-input-container> 
      <input mdInput placeholder="County" [disabled]="this.personalDetailsDisable" [(ngModel)]="accountService.client?.address.county"> 
     </md-input-container> 
     <md-input-container class="containerRightMargin"> 
      <input mdInput placeholder="Country" [disabled]="this.personalDetailsDisable" [(ngModel)]="accountService.client?.address.country"> 
     </md-input-container> 
     <md-input-container> 
      <input mdInput placeholder="Postcode" [disabled]="this.personalDetailsDisable" [(ngModel)]="accountService.client?.address.postCode"> 
     </md-input-container> 
</md-card> 

我不知道如何檢查,我可以檢查所有字段之一。原因是,除非任何字段值從我的服務返回的默認值更改,然後我想'保存'按鈕來顯示其他明智我不希望保存按鈕顯示。

我知道這在我的組件來完成,並且我已經看到SimpleChange等的例子,但我不能讓它在所有

回答

1

工作,如果你可以分享你的組件的源代碼,我們可以看到更多。但到目前爲止,應該這樣做。 Link to Angular docs.

@Component({selector: 'my-cmp', template: `...`}) 
class MyComponent implements OnChanges { 
    @Input() 
    prop: number; 

    ngOnChanges(changes: SimpleChanges) { 
    // changes.prop contains the old and the new value... 
    } 
}