【发布时间】:2017-09-16 12:41:44
【问题描述】:
我正在学习 AngularJS 并设置了项目的结构,但 JSON 无法在 html 中显示。
我是 Angularjs 的新手。如何使用 ng-repeat 指令将 JSON 显示到我的 html 中的数据。我的 HTML 是:
有人建议我如何使用 json.?
<div ng-repeat="qd in quiz">
<p>{{qd.question}} </p>
<p>{{qd.id}} </p>
<ul>
<li>{{qd.possibilities[0]}} </li>
<li>{{qd.possibilities[1]}} </li>
<li>{{qd.possibilities[2]}} </li>
<li>{{qd.possibilities[3]}} </li>
</ul>
</div>
脚本:
myApp.controller('appCtrl', ['$scope', '$http', function($scope, $http) {
$scope.quiz = [{
question: "1 what is the typical lifespan of a green sea turtle ?",
id: 1,
possibilities: [{
answer1: "150 years"
},
{
answer2: "10 years"
},
{
answer3: "80 years"
},
{
answer4: "40 years"
}
]
},
{
question: "2 what is the typical lifespan of a green sea turtle ?",
id: 2,
possibilities: [{
answer1: "250 years"
},
{
answer2: "20 years"
},
{
answer3: "160 years"
},
{
answer4: "20 years"
}
]
}
];
}]);
【问题讨论】:
标签: javascript jquery angularjs json angularjs-ng-repeat