Dynamic template based on value rather than variable with ngTemplateOutlet

前端 未结 3 1865
花落未央
花落未央 2021-01-13 04:51

I\'m trying to mock up a dynamic set of questions. Think of a quiz, where one question is multiple choice, the second is single answer, the third is yes no..etc.

Us

3条回答
  •  囚心锁ツ
    2021-01-13 05:32

    **You can change your approach a little bit as it is an optional suggestion **

    @Component({
      selector: 'my-component',
     template: `
       
    checkboxes here {{item?.type}} - {{item?.values}} radio buttons here{{item?.type}} - {{item?.values}} boolean here{{item?.type}} - {{item?.values}} textbox here{{item?.type}} - {{item?.values}} ` }) export class MyComponent { @Input() items: any[]; }

    You can call your template's based on your "item.type", Rest of the structure looks good in your approach.

提交回复
热议问题