У меня есть этот компонент с этим шаблоном:
@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)
}
}
Мне нужно знать, как добавить поля ввода в TemplateRef и добавить их в свою форму.
// редактировать Поля ввода должны существовать только в форме внутри компонента, а не в форме, которая находится в основном приложении.
Вы можете проверить пример по этой ссылке: https://plnkr.co/edit/cWWxRUlMfR6ecNbga8Y7?p=preview