Search code examples
angularangular4-formsformgroups

Trigger valueChanges from patchValue with custom flags


There is a way that I can see custom flags in the event valueChanges of a FormGroup when I do a patchValue in an specific piece of code?

ex. I have to do a patchValue in an specific piece of code and the form is quite large, when I do that there is some stages that the values changes and I want to subscribe and treat that information but I want to categorize that special call form that patchValue.

Any ideas? Thanks in advance.


Solution

  • Well, no, of course the Observable gets a value a emitted when you call the patchValue method, but no other info, just what the new value is. You cannot interfere with the inner workings.

    But another point is... if you really have logic that should work exactly after that specific change on the form and is not some kind of generic logic, then why place it anywhere but after the patchValue call? It's counterintuitive and I think a bad idea

    Just go with

    this.form.patchValue(someValue);
    // your specific logic goes here