Reputation: 31
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.
Upvotes: 1
Views: 1057
Reputation: 1684
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!
Upvotes: 4