【发布时间】:2022-01-18 16:04:54
【问题描述】:
我正在使用 Ionic 和 Angular 创建一个简单的 MCQ 论文。我正在尝试根据 JSON 数据文件呈现有角度的可重用组件。在我的 JSON 数据数组中,存在三种类型的 mcq 问题。另外,我有三个可重用的组件,我需要根据 mcq 的类型来渲染它们。我已经使用 for 循环检查了 MCQ 的类型,但我不知道如何从 ts 文件调用组件。
这是我的 JSON 数据文件
"questions": [
[
{
"index": 1,
"type": "single-select",
"text": "If 5x plus 32 equals 4 minus 2x what is the value of x ?",
"answers": [
{
"index": "A",
"value": "-4"
},
{
"index": "B",
"value": "-3"
},
{
"index": "C",
"value": "4"
},
{
"index": "D",
"value": "7"
},
{
"index": "E",
"value": "12"
}
],
"correctAnswers": {
"indexes": [
"A"
]
},
"points": "10",
"time": "30"
}
],
[
{
"index": 2,
"type": "multi-select",
"text": "let X * Y = 12. What are the possible values for X and Y ?",
"answers": [
{
"index": 1,
"value": "X=4 and Y=3",
"isChecked": false
},
{
"index": 2,
"value": "X=8 and Y=2",
"isChecked": false
},
{
"index": 3,
"value": "X=6 and Y=2",
"isChecked": false
},
{
"index": 4,
"value": "X=3 and Y=5",
"isChecked": false
},
{
"index": 5,
"value": "X=1 and Y=1",
" isChecked": false
}
],
"correctAnswers": {
"indexes": [
1,
3,
5
]
},
"points": "10",
"time": "30"
}
],
[
{
"index": 3,
"type": "dropdown-select",
"text": "What is the 3rd color of the rainbow ?",
"answers": [
{
"index": 1,
"value": "Green"
},
{
"index": 2,
"value": "Red"
},
{
"index": 3,
"value": "Yellow"
},
{
"index": 4,
"value": "Pink"
},
{
"index": 5,
"value": "Blue"
}
],
"correctAnswers": {
"indexes": [
3
]
},
"points": "10",
"time": "30"
}
],
]
我使用@Input 和@Output 创建了可重用的组件。谁能帮帮我?
【问题讨论】:
-
为什么要在ts文件中实现这个?您可以做的是在模板中实现循环,并使用开关可以渲染其中一个组件。
标签: angular typescript ionic-framework