Mike Mike - 20 days ago 14
TypeScript Question

Angular2 Trigger form.valueChanges manually

I'm subscribing to my form changes with:

this.form.valueChanges.subscribe(formData => { // Data is saved here. });


When I click a button in my form it changes one of the input values. Somehow the valueChanges subscribe is not being triggered. Can I do this manually?

Answer

I believe you need to map the valuechanges before subscribing like:

 this.physicalForm.valueChanges
       .map((value) => {
          return value;
       })
       .subscribe((value) => {
         this.selectedPhysical.activityLevel = this.physicalForm.value.activityLevel;
       });