I am trying to detect changes to the properties of a model called 'invoice
' so that a button can be enabled only when the values of this object are not the same as those of the initial model, 'initModel
', created when the component was initialised.
So I need to be able to compare the two in the view like this:
<button mat-button (click)="saveChanges()" [disabled]="invoice !== initModel">Save Changes</button>
The 'invoice' model is initialised by giving it the value of another variable from a service in the constructor.
I've tried to figure out a way of setting an 'initModel' component variable, but this obviously binds with the 'invoice' model, so when the 'invoice' changes, the 'initModel' changes as well, and I can't set 'initModel' as a const that can be accessed in the view.
Component:
export class EditInvoiceComponent implements OnInit {
invoice: Invoice;
initModel;
constructor(private invoicesService: InvoicesService) {
this.invoice = this.invoicesService.selectedInvoice;
this.initModel = this.invoice;
}