Pavan
Pavan

Reputation: 31

Angular2 dynamic form checkbox

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

Answers (1)

Ha Hoang
Ha Hoang

Reputation: 1684

You have to create new checkbox control and include it in the dynamic form.

  1. 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'] || '';
        }
    }
    
  2. Add new question item

    new CheckboxQuestion({
            key:'agree',
            label:'I Agree',
            type: 'checkbox',
            value:'false',
            order: 4
        })
    
  3. Include it in the dynamic form

Here works for me.

Hope this help!

Upvotes: 4

Related Questions