【发布时间】:2021-12-26 18:34:54
【问题描述】:
我的 component.ts 代码是
forms = new FormGroup({
topics: new FormArray([]),
});
addTopic(topic: HTMLInputElement) {
(this.refForm as FormArray).push(new FormControl(topic.value));
// topic.value = '';
}
get refForm() {
return this.forms.get('topics');
}
.html 文件有以下代码。
<form [formGroup]="forms">
<input
type="text"
class="form-control"
(keyup.enter)="addTopic(topic)"
#topic
/>
<ul class="list-group">
<li *ngFor="let topic of forms.get('topics')">
class="list-group-item">
{{ topic.value }}
</li>
</ul>
</form>
我试图找到并解决问题,但没有解决方案或答案。
【问题讨论】: