【发布时间】:2019-04-08 19:51:53
【问题描述】:
我有一个 ng-template,它是从我的一个组件传递过来的,我有一个占位符来接受传递到我的组件上的 ng-template,如下 ngTemplateOutlet 所示。
<div>
<form novalidate #myForm="ngForm">
<ng-container>
<ng-template [ngTemplateOutlet]="myTemplate">
</ng-template>
</ng-container>
</form>
</div>
<!-- this template i am passing it from one of my other components -->
<ng-template #myTemplate>
<input type="text" name="myInput" placeholder="Input"
[(ngModel)]="inputModel" required/>
</ng-template>
这里的问题是我的表单('myForm')忽略了传递的 ng-template,即使它被标记为必需。我如何确保我的 ngForm 考虑传递的 ng-template
【问题讨论】:
-
已经尝试过此修复但没有运气 - stackoverflow.com/questions/39242219/…。如果我可以使用上面示例中提供的指令来处理它会更好
-
如果在容器上设置模板出口?
<ng-container *ngTemplateOutlet="myTemplate"></ng-container>文档:NgTemplateOutlet -
试过了没啥区别
-
你有解决办法吗?我有同样的问题
-
saravana va 下面的解决方法工作正常。这可能是 Angular
ngTemplateOutlet中的一个错误
标签: angular nested-forms angular-forms ng-template