所以我在这里使用了指南:https ://angular.io/docs/ts/latest/cookbook/dynamic-form.html
我需要向现有字段添加更多字段。我做了一些有用的东西,但它很笨重,当我点击它时它会重置表单。下面的代码:
在动态-form.component.ts 中:
add_textbox()
{
this.questions.push(this.questionService.create_textbox({key: "test", label: "Test"}));
console.log(this.questions);
this.form = this.qcs.toFormGroup(this.questions);
}
有问题.service.ts
create_textbox({key, value, label = '', order = 1, type = "text", description = "", help = ""}: {key?: any, value?: any, label?: any, order?: any, type?: any, description?: any, help?: any})
{
return new TextboxQuestion({
key,
label,
value,
order,
description,
type
});
}
我的按钮也在里面,dynamic-form.component.html但我希望它在里面dynamic-form-question.component.ts。这可能吗?