So I used the guide here: https://angular.io/docs/ts/latest/cookbook/dynamic-form.html
I need to add more fields to an existing field. I've made something that works, but it's clunky and it resets the form when I hit it. Code below:
In 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
});
}
My button is also in dynamic-form.component.html
but I'd like it to be in dynamic-form-question.component.ts
instead. Is this possible?
The winning solution might be a bit outdated. Code to works with new ng'6 syntax would look more or less like this:
controller:
and with html like this:
first of all
then
Begin and close your HTML with:
<div formArrayName="linktodrive"></div>
For creating and removing dynamic fields to your form use this html:
And finally the "ADD" link