I have a scenario where I'm trying to show radio buttons say one question has two answers as 1) Veg 2)Non-veg ,so when i select veg it has further three options and the third option "Mixture of Vegetable and Fruits" has further question inside it and so on.
The following is the reference json that I'm using
"choices": {
"1": {
"text": "Vegeterian",
"questions": {
"1": {
"choices": {
"1": { "text": "Only Veggies" },
"2": { "text": "Only Fruits" },
"3": {
"text": "Mixture of Vegetable and Fruits",
"questions": {
"1": {
"type_name": "selectOne",
"choices": {
"1": {
"text": "Yes.. No animal product",
"questions": {
"1": {
"type_name": "selectOneOrMore",
"choices": {
"1": {
"text": "You are a nice human being"
},
"2": {
"text": "You are a good human being"
}
}
}
}
},
"2": {
"text": "No meat. but other animal product"
}
}
}
}
}
}
}
}
},
"2": { "text": "Non-Vegeterian"}
}
and on the angular front I have just shown the outer two option ,how can i dynamically on selection of the radio button add further question if it has further questions and option
<ng-container *ngFor="let consult of choices | keyvalue; let j = index; trackBy: trackByFn;">
<td>
<input type="radio" name="radio" id="radio-{{j}}" />
<label class="sr-text" for="radio-{{j}}">{{consult.value.text}}</label>
</td>
</ng-container>
ng-ifto render item based on conditions, knowing thatng-ifwill not add the item to DOM till the condition met, and when condition fail it'll remove it from DOM, as well as you might give this link stackoverflow.com/questions/44411991/… a look