I am having a data as below. There are 2 types of questions one which have pictures as answer and other which has options as answer.
$scope.data = [
{'question': "Select one.", 'pic': false,
'answer': [
{"option": "8", "correct": false},
{"option": "14", "correct": false},
{"option": "1", "correct": true},
{"option": "23", "correct": false}
]
},
{'question': "Select another right answer.", 'pic': true,
'answerPic': [
{"option": "img/pic1.jpeg", "correct": false},
{"option": "img/pic2.jpeg", "correct": false},
{"option": "img/pic3.jpeg", "correct": true},
{"option": "img/pic6.jpeg", "correct": false}
]
},
]
I have used the below code to present them in the view. As you can see there are two block of ng-repeat
, one for each type. But how do I make angular choose a particular type looking the pic value in the data? For example if pic is true angular should use the block for picture. And otherwise the normal one.
<div class="text">
<label ng-repeat="a in question.answer">
<input type="radio" name="answers">
<div class="item-content">
{{ a.option }}
</div>
</label>
</div>
<div class="picture">
<label ng-repeat="a in question.answer">
<input type="radio" name="answers">
<div class="item-content">
<img src="{{ a.option }}" />
</div>
</label>
</div>
As of now, the only option that I can think of is, using ng-show
and ng-hide
. Then I will be able to pass the pic
value from data to it. But it looks like a hack to me. What would be the best way to solve this kind of a scenario?