1

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 1

4

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!

Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.