1

I have a nested form similar to the following:

profileForm = new FormGroup({
  firstName: new FormControl(''),
  lastName: new FormControl(''),
  address: new FormGroup({
    street: new FormControl(''),
    city: new FormControl(''),
    date1: new FormControl(''),
    date2: new FormControl('')
  })
});

I'm trying to set the date2 mindate as date1 value like this:

<mat-form-field class="datepickerformfield" floatLabel="never">
    <input matInput class="dp" formControlName="date2" [min]="profileform.controls['date1'].value" [matDatepicker]="date2" placeholder="DD/MM/AAAA" >
</mat-form-field>

Also tried with:

[min]="profileform.address.controls['date1'].value"

And

[min]="profileform.controls[address].controls['date1'].value"

But I get an error:

Cannot read property 'value' of undefined

How can I get the date1 value with the profileform object?

3
  • Can you share it in stackbiltz Commented Oct 4, 2019 at 6:20
  • 2
    profileForm.get('address').get('date1') Commented Oct 4, 2019 at 6:23
  • [min]="profileform.get('address').get('date1').value", or [min]="profileform.get('address.date1').value" Commented Oct 4, 2019 at 6:29

2 Answers 2

2

Finally solved with:

[min]="profileform.get('address.date1').value"

Working on Angular6+

Sign up to request clarification or add additional context in comments.

Comments

0

The form has am member called value which is a reflection of your form structure but only including the values. To access the date you simply should call [min]="profileform.value.address.date1".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.