I have Angular form (not reactive), with data binded in ngModel:
<form #form="ngForm"> <input [(ngModel)]="user.name"> <input [(ngModel)]="user.color"> <button type="submit">Save</button> </form>
How can i disable submit button if binded data has not been changed?
You can use rxjs operators to check values.
if you want to see if the form is dirty you should check the viewModel in kendo way sample. basically I've created a viewModel which is impements the ObservableObject interface and has a two way binding with the form's container.
ValueChanges of FormGroup The ValueChanges event of FormGroup or FormArray is fired, whenever the value of any of its child controls value changes.
You can check the dirty flag, which tells you if the form is dirty or not.
<button type="submit" [disabled]="!form.dirty">Save</button>
The form becomes dirty if you change some value in it.
Check here for more details: https://angular.io/guide/forms
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With