How do you listen for dirty/pristine state of the form control?
See original GitHub issueI’ve posted this question on StackOverflow recently: How do I know when custom form control is marked as pristine in Angular?.
After further investigation, I’ve managed to get access to both NgModel
and FormControl
from my custom form component, but I can’t find any observable that I can use to actually listen for dirty/pristine state of the form control. The ControlValueAccessor
is not providing any hooks for this task either.
Is it possible to watch for dirty/pristine state of the form control somehow? There must be an observable for this?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:24
- Comments:28 (6 by maintainers)
Top Results From Across the Web
How to listen on dirty/pristine status in Angular 6
You don't need each such call - only the first one (when the form GETS DIRTY). So it's not the best approach you...
Read more >Monkey Patching A Touched/Dirty/Pristine Event Listener In ...
To my surprise, there is currently no event that is emitted when a control is touched – or when it's status of pristine/dirty...
Read more >Input controls remain dirty and not pristine after form.reset() in ...
When calling form.reset() after changing a controls value, I would expect the controls to be reset to dirty: false, pristine: true, touched: false....
Read more >Angular Form Pristine, Dirty, Touched & Status - YouTube
Angular Tutorial:#angular #angulartutorial #nitishkaushikGitHub Repo: ...
Read more >Detect Unsaved Changes in Angular Forms | by Netanel Basal
When the beforeunload event emits, we check if the component is dirty. If it is, we set the returnValue to false, which will...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You can listen to an
AbstractControl#statusChanges
eg,control.statusChanges.map( state => if(state == 'VALID" { //do something })
I’ve came up with two possible workarounds for the original issue:
Monkey-patching the
markAsPristine()
Watching for changes with
ngDoCheck
I’ve also updated the questions on StackOveflow: