I have this component with this template:
@Component({
selector: 'form-component',
template:`
<form #form="ngForm" (ngSubmit)="formComponentSubmit(form)">
<ng-container #tmlContainer></ng-container>
<button type="submit">Component form submit</button>
</form>`
})
export class FormComponent implements OnInit{
@ViewChild('tmlContainer', {read: ViewContainerRef}) tmlContainer;
@Input() templateIn: TemplateRef<any>;
ngOnInit() {
this.tmlContainer.insert(this.templateIn.createEmbeddedView(null));
}
formComponentSubmit(form) {
console.log('Component', form)
}
}
I need to know how can I get the input fields added into the TemplateRef and add it to my form.
//edit The input fields must exist only in the form of inside the component and not on the form that is in the main app.
You can check the example in this link: https://plnkr.co/edit/cWWxRUlMfR6ecNbga8Y7?p=preview