【发布时间】:2020-02-24 06:04:46
【问题描述】:
我想在表格行内显示表格。每行都有因素明智的自我评价功能。用户可以编辑个人因素评级。所以我想显示每一行在稍后编辑和更新时都具有插入功能。这就是为什么我在表格内使用表格,但 formGroup 出现错误。然后在我使用表格之前的表格之后。我有同样的错误。 这是我的错误
**Uncaught Error: Template parse errors:
Can't bind to 'formGroup' since it isn't a known property of 'form'**.
这是我的代码 .html 文件
`<form [formGroup]="appraisalApplyForm" (ngSubmit)="submitApplyAppraisal()">
<table class="table table-bordered" style="overflow-y: auto;">
<thead>
<tr>
<th class="pdten">Rating Factors</th>
<th class="pdten">Self Appraisal Rating </th>
<th class="pdten">Supervisor Appraisal Rating</th>
<th class="pdten">Justification/Remark</th>
<th class="pdten">Action</th>
</tr>
</thead>
<tbody>
<ng-container *ngFor="let factor of factors; index as i">
<tr *ngIf="factor.department_id ===parameter.id">
<!-- <form method="post" [formGroup]="appraisalApplyForm" (ngSubmit)="submitApplyAppraisal()"> -->
<td class="pd_custom fw " >{{factor.rating_factor_name}}</td>
<input type="hidden" formControlName = "department_id" value="{{parameter.id}}"/>
<input type="hidden" formControlName = "factor_id" value="{{factor.id}}"/>
<td><input class="form-control" id="" placeholder="Enter Rating.." type="text" formControlName = "self_rating[]"></td>
<td><input class="form-control" id="" placeholder="Enter Rating.." type="text" formControlName = "supervisor_rating[]"></td>
<td>
<textarea class="form-control" id="" placeholder="remark.." formControlName = "remark[]"></textarea>
</td>
<td><input type="submit" class="btn bg-olive btn-flat margin " value="submit"></td>
<!-- </form> -->
</tr>
</ng-container>
</tbody>
</table>
<div class="box-footer">
<input type="submit" class="btn bg-olive btn-flat margin " value="submit">
</div>
</form>`.
.ts 文件代码
export class AppraisalApplyComponent implements OnInit {
appraisalApplyForm :FormGroup;
constructor(private _services: ApiService, private router: Router, private fb: FormBuilder,
private http: HttpClient) { }
factors:any;
parameters:any;
data = {
}
ngOnInit() {
this.getRatingFactorParameter();
this.getRatingFactors();
this.appraisalApplyForm = this.fb.group({
factor_id: [''],
department_id: [''],
self_rating: [''],
supervisor_rating: [''],
remark: [''],
//arr: this.fb.array([])
});
}
submitApplyAppraisal(){
let route = 'add-apply-appraisal';
let data = this.appraisalApplyForm.value;
alert(data);
return ;
const token = localStorage.getItem('token')?localStorage.getItem('token'):'';
console.log(data);
this._services.requestCreator(data, route, token).subscribe((result: any) => {
console.log(result.result);
if (result.status = 200) {
alert('Rating Factor Data Added Successfully !.');
console.log("Form Submitted!");
// this.applyAppraisalForm.reset();
}
});
欢迎任何关于更好编码的建议。
【问题讨论】:
-
你导入 ReactiveFormsModule 到你的模块了吗?
-
是的。我已经导入了这个