Angular 角度2。如何以反应形式使用formArray
我对剑道角网格中的反应形式有问题。 我的模型(书)有一组作者,我想在网格列中显示这些作者。但我没有找到任何关于如何以反应形式处理集合的信息。因此,我的模板无法正确显示数据 这是我在formGroup中的作者收藏:Angular 角度2。如何以反应形式使用formArray,angular,typescript,angular-reactive-forms,kendo-ui-angular2,Angular,Typescript,Angular Reactive Forms,Kendo Ui Angular2,我对剑道角网格中的反应形式有问题。 我的模型(书)有一组作者,我想在网格列中显示这些作者。但我没有找到任何关于如何以反应形式处理集合的信息。因此,我的模板无法正确显示数据 这是我在formGroup中的作者收藏: this.formGroup = createFormGroup({ genre: { genreId: 0, genreName: '' }, 'bookName': '', 'pages': 0, 'publisher': '', //her
this.formGroup = createFormGroup({
genre: {
genreId: 0,
genreName: ''
},
'bookName': '',
'pages': 0,
'publisher': '',
//here
authors: new Array<Author>()
});
<kendo-grid-column field="authors" title="Authors" width="250">
<ng-template kendoGridCellTemplate let-dataItem>
<div *ngIf="dataItem.authors">
<ul>
<li *ngFor="let author of dataItem.authors">
<strong>{{author.authorsName }}</strong>
</li>
</ul>
</div>
</ng-template>
const createFormGroup = dataItem => new FormGroup({
'bookId': new FormControl(dataItem.bookId),
'bookName': new FormControl(dataItem.bookName, Validators.required),
'pages': new FormControl(dataItem.pages),
'publisher': new FormControl(dataItem.publisher),
'genre': new FormControl(dataItem.genre, Validators.required),
'authors': new FormArray(dataItem.authors)
});
表单控件初始化:
this.formGroup = createFormGroup({
genre: {
genreId: 0,
genreName: ''
},
'bookName': '',
'pages': 0,
'publisher': '',
//here
authors: new Array<Author>()
});
<kendo-grid-column field="authors" title="Authors" width="250">
<ng-template kendoGridCellTemplate let-dataItem>
<div *ngIf="dataItem.authors">
<ul>
<li *ngFor="let author of dataItem.authors">
<strong>{{author.authorsName }}</strong>
</li>
</ul>
</div>
</ng-template>
const createFormGroup = dataItem => new FormGroup({
'bookId': new FormControl(dataItem.bookId),
'bookName': new FormControl(dataItem.bookName, Validators.required),
'pages': new FormControl(dataItem.pages),
'publisher': new FormControl(dataItem.publisher),
'genre': new FormControl(dataItem.genre, Validators.required),
'authors': new FormArray(dataItem.authors)
});
还开始检查html中的值
<ng-template kendoGridCellTemplate let-dataItem>
<div *ngIf="!dataItem.authors==null">
{{log(dataItem.authors)}}
{{log(formGroup.authors)}}
<ul>
<li *ngFor="let author of dataItem.authors">
{{log(author)}}
<strong>{{author.authorName }}</strong>
</li>
</ul>
</div>
</ng-template>
我没有找到任何关于如何在反应式表单中使用集合的信息:这里是关于反应式表单的官方文档:。但似乎您想要显示信息,那么为什么需要表单呢?表单用于输入和提交信息。我使用剑道网格进行角度分析,剑道使用反应表单编辑网格中的数据。为了简洁起见,我缩短了代码,我的模板是网格列的一部分。这个问题仍然相关