【发布时间】:2017-05-06 12:39:13
【问题描述】:
所以我在这里使用了指南:https://angular.io/docs/ts/latest/cookbook/dynamic-form.html
我需要向现有字段添加更多字段。我做了一些有用的东西,但它很笨重,当我点击它时它会重置表单。代码如下:
在dynamic-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);
}
in question.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 中。这可能吗?
【问题讨论】:
标签: forms angular angular2-forms angular2-formbuilder