【发布时间】:2020-09-06 19:02:18
【问题描述】:
// Getter function:
get getCheckboxes_FormGroup()
{
return this.objFormGroup.controls.checkboxesBlogs.controls as FormArray;
}
ngOnInit()
{
this.objFormGroup = this.objFormBuilder.group(
{
checkboxesBlogs: new FormArray([])
}
)
for( var i = 0; i < this.blogs.length; i++)
{
// Generate a checkbox for this blog:
this.getCheckboxes_FormGroup.push( this.objFormBuilder.group(
{
blogTitle: [this.blogs[i].title],
blogId: [this.blogs[i].id],
checkboxValue: [false],
body: [this.blogs[i].body],
creationDate: [this.blogs[i].creationDate],
modificationDate:[this.blogs[i].modificationDate],
category: [this.blogs[i].category],
visible: [true]
}
)
);
}
}
在打字稿中,我尝试像这样访问它:this.getCheckboxes_FormGroup.controls[i].value.visible = false
这不会给我错误,但它也没有将值设置为 false。
在 HTML 中,我尝试像这样访问它:<div *ngFor = "let checkboxesBlog of getCheckboxes_FormGroup.controls; " >
<a *ngIf = "checkboxesBlog.controls.visible.value === true">
这并没有给我错误,但它始终显示价值为真。
在 typescript 和 html 中访问它的适当方式是什么?
【问题讨论】:
标签: html angular typescript angular-reactive-forms