【发布时间】:2019-10-30 09:21:30
【问题描述】:
在这里,我想让 FormArray 的长度为零。 (据说这个表格一切正常)
profileForm: FormGroup;
ngOnInit() {
this.profileForm = new FormGroup({
nod_title: new FormControl(),
nod_subtitle: new FormControl(null),
nod_name: new FormControl(null),
nod_occupation: new FormControl(null),
nod_description: new FormControl(null),
nod_tags: new FormArray([new FormControl('hello'), new FormControl('world')]),
});
}
resetTags() {
if (this.profileForm.value.nod_tags.length) { // here I tried
this.profileForm.value.nod_tags.clear();
console.log(this.profileForm.value.nod_tags)
}
<button type="button" (click)="resetTags()"> Reset taggs </button>
这里,我想清空 nod_tags 的值,console.log() 应该返回一个空数组。
【问题讨论】:
-
this.profileForm.get('nod_Tags').clear(),参见文档,angular.io/api/forms/FormArray#clear
标签: angular