1

Can someone explain why the numeric values show as an empty string within my formGroup,

  private formatFormValues(depositDates) {
    return depositDates.map((depositDate) => {
      console.log('deposit dates', depositDates);
      console.log('deposit dates - amount', depositDate.controls.effectiveDates.value);
      return {
        effectiveDates: depositDate.controls.effectiveDates.value,
        depositDate: depositDate.controls.depositDate.value,
      };
    });
  }

I have this depositDates formGroup instance which Im logging and looks like this: enter image description here

I then try to access the values within this instance, and for some reason the amount always shows as an empty string despite it being shown as an active and set numeric value?

enter image description here

Am I in some what missing something / accessing something incorrectly for this to happen?

3
  • Show your html also Commented Feb 19, 2019 at 11:21
  • This is being run on page load fyi Commented Feb 19, 2019 at 11:24
  • Is the formGroup expecting a string or a number for amount? It looks like it is looking for a string. It could also be an issue with the return not waiting for the map to finish. I will put a code snippet in an answer below. Commented Feb 19, 2019 at 11:26

3 Answers 3

2

Maybe the method returns values before the map function finishes? You can try the code below..

async formatFormValues(depositDates) {
        return new Promise(async (resolve, reject) => {
            resolve(depositDates.map(async (depositDate) => {
                console.log('deposit dates', depositDates);
                console.log('deposit dates - amount', depositDate.controls.effectiveDates.value);
                return {
                    effectiveDates: depositDate.controls.effectiveDates.value,
                    depositDate: depositDate.controls.depositDate.value,
                };
            }));
        });

    }

When you access it you can use:

this.formatFormValues(depositDates).then(resp => {
    // set form values
});
Sign up to request clarification or add additional context in comments.

Comments

1

Sometimes, Angular is not being notified to update the value of a form group. You can manually call updateValueAndValidity on your form group or the required form control.

Comments

0

Turns out I had an option param in my setValue() call stopping any event emitting, still dont understand why it would access the amount value despite it being there prior to my changes, answer goes to anyone who can explain..

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.