I had a situation where I did not have a form, adapting it to the question asked here, although mine handles on click and not disabling the button. Angular 7 with TypeScript:
<!-- user.component.html -->
.....
.....
<div>
<input [(ngModel)]="user.name">
<input [(ngModel)]="user.color">
<button (click)="save()">Save</button>
</div>
// user.component.ts
.....
.....
lastObjectHash: string;
User: user = { name: "joe", color: "blue"}; // with name and color on type User
// Not really a hash, but let's call it that
getObjectHash(): Promise<string> {
return util.encodeBase64(JSON.stringify(this.user));
}
ngAfterViewInit(): void {
this.getObjectHash().then(value => this.lastObjectHash = value);
}
save() {
this.getObjectHash().then(value => {
if (this.lastObjectHash === value) {
alert("You did not change name or color");
return;
}
// Save user changes....
this.userService.save(this.user); // Or whatever...
});
}
// util.ts
// Just a utility function to BASE64 encode
.....
.....
export const encodeBase64 = async (textString) => {
return btoa(textString);
};