I am trying to implement dynamic form in Angular2 and I have gone through https://angular.io/docs/ts/latest/cookbook/dynamic-form.html but it has components only for text box and dropdown, I have to populate my dynamic form with check boxes and radio buttons, not sure how to do that. Any help is appreciated. Thanks in advance.
1 Answer
You have to create new checkbox control and include it in the dynamic form.
Create new checkbox control named app/question-checkbox.ts as:
import { QuestionBase } from './question-base'; export class CheckboxQuestion extends QuestionBase<string> { controlType = 'checkbox'; type: string; constructor(options: {} = {}) { super(options); this.type = options['type'] || ''; } }Add new question item
new CheckboxQuestion({ key:'agree', label:'I Agree', type: 'checkbox', value:'false', order: 4 })Include it in the dynamic form
Here works for me.
Hope this help!
1 Comment
Pavan
thanks for your help, but here you are consuming data from one of your components but I have to consume data from API, that is where I am facing problem with... @Meligy