angular - ngTemplate 和 ngContainer 中的 FormControl
问题描述
我有一个工作角度形式,在两个条件下重复模板,所以我将它移到一个公共位置并定义 ngContainer 以通过传递变量来显示值,但是在模板内部,代码无法找出形式我得到以下错误
BulkEditComponent.html:28 ERROR Error: formControlName must be used with a parent formGroup directive. You'll want to add a formGroup
directive and pass it an existing FormGroup instance (you can create one in your class).
模板
<h5 mat-dialog-title>
Edit
</h5>
<div mat-dialog-content class="body p-10">
<div *ngFor="let item of keyList;let i=index" [formGroup]="editForm">
<div class="left" *ngIf="i%2 == 0">
<ng-container *ngTemplateOutlet="columnData;context:{item:item,group: editForm}"></ng-container>
</div>
<div class="right" *ngIf="i%2 == 1">
<ng-container *ngTemplateOutlet="columnData;context:{item:item,group: editForm}"></ng-container>
</div>
</div>
</div>
<mat-dialog-actions class="align-right">
<button mat-button mat-dialog-close>Cancel</button>
<button mat-flat-button color="primary" (click)="formatData()">Update</button>
</mat-dialog-actions>
<ng-template #columnData let-item='item' ;let-formGroup="editForm">
<div class="row p-2">
<div class="col-md-6">
{{getColumnName(item)}}
</div>
<div class="col-sm-6">
<input type="text" class="input-field" [formControlName]="item" />
</div>
</div>
</ng-template>
解决方案
推荐阅读
- compiler-errors - ld:找不到-lSystem collect2的库:错误:ld返回1退出状态gfortran
- python-3.x - 刮硒保护地
- c++ - 使用openmp实现并行广度优先搜索
- python - Python 从错误的目录导入包(在 virtualenv 之外)
- ruby-on-rails - 在 Ruby on Rails HTML 文件中检查 verify_recaptcha 的结果
- ionic-framework - 如何从离子中的查询字符串中获取参数?
- c - 在链表中,程序在进入结构的成员时关闭
- c++ - 使用 C++ 的正则表达式
- java - MacOSX 升级后 Qualimap 中的“JAVA Parse Exception”错误
- awk - 在总和之后将数据拆分为特定值