2

i need advice! I want validate reactive form. I have two form groups and both have input with same formcontrolname.

my code:

  this.form = this.fb.group({
  group1: this.fb.group({
    name: ['', Validators.required],
  }),
  group2: this.fb.group({
    name: [ '', Validators.required],
  })
});

How cen i get both of name?

I tried this. But i dont know which one i get.

get name() { return this.form.get('name'); }

Thanks!

3 Answers 3

0

just used this statement, it should work : )

get name() { return this.form.get('group1.name').value; }
Sign up to request clarification or add additional context in comments.

1 Comment

0

With such structure:

this.form = formBuilder.group({
'varA': [],
'varB': formBuilder.group({
  'varC': []
(...)

Accessing looks like this:

varA = this.form.value['varA']
varC = this.form.value['varB']['varC'];

If I got your question correctly.

Comments

0

You can use this function in component

 get name() { 
       return this.form.controls['group1'].value.name;
    }

1 Comment

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.