1

I use Angular7 with Angular Material, I have a form which contain a component which contain a mat-select. The select in the form out of my component work but not the one into my component.

Viewable on this stackblitz : https://stackblitz.com/edit/angular-hqkcgq

The actual result is that submiting form don't send the value of the select, but it have to. You can see in console when submiting the form.

edit: the stackblitz is edited and now work as I want

0

1 Answer 1

2

For future, please add all relevant code to the question itself. A StackBlitz is great, but it should just be an addition to the question :)

But to your code, in your child component you need to provide ControlContainer. So add to your code:

import { ControlContainer, NgForm } from '@angular/forms';

@Component({
  selector: 'my-comp',
  templateUrl: './my-comp.component.html',
  viewProviders: [ { provide: ControlContainer, useExisting: NgForm } ]
})

Please refer to the article by the awesome Alexey Zuev: Nested Template driven Forms

As a sidenote, in all places you are providing [ngModel]="''", you can just use ngModel to register the form control.

Your forked StackBlitz

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

1 Comment

Thanks a lots, for the [ngModel], its because I take it from mycode where I have to use [], thanks too for the link, I didn't found it during my research

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.