服务器中的 Angular 5 项目我必须接收多个项目以保存在数据库中..
在角度方面,我试图创建一个表单来传递多个项目......
当按下添加另一个输入供用户添加另一个项目时我需要一个按钮我几乎完成但我不知道如何保持输入在一起我尝试了一些链接但它不起作用你能告诉我我该如何解决这个问题吗?
我的组件:
export class RequirementFormComponent implements OnInit {
private requirment: Requirement;
orderForm: FormGroup;
items: FormArray;
constructor(private form: FormDataService, private formBuilder: FormBuilder, private router: Router) {
}
ngOnInit() {
this.requirment = this.form.getRequirment();
this.orderForm = this.formBuilder.group({
items: this.formBuilder.array([this.createItem()])
});
}
addItem(): void {
this.items = this.orderForm.get('items') as FormArray;
this.items.push(this.createItem());
}
}
createItem(): FormGroup {
return this.formBuilder.group({
item: '',
});
}
html:
<ul class="eff">
<li>
<div>
<form [formGroup]="orderForm" class="editForm" novalidate>
<div class="input-field" *ngFor="let item of orderForm.get('items').controls; let i = index;">
<input class="form-control" formControlName="items" [ngModel]="item"
type="text" maxlength="50">
</div>
</form>
</div>
</li>
</ul>