我正在学习AngularJS,并设置了项目的结构,但JSON无法在html中显示。如何使用Angularjs显示Json?
我是Angularjs的新人。如何使用ng-repeat指令在我的html中显示JSON数据。我的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"
}
]
}
];
}]);
感谢您的回复, 但它表现出充分的价值像目的。 ,我只想回答像“150年” 是我的JSON是错的? – user1727852
@ user1727852检查更新的答案 – Sajeetharan
@ user1727852你为什么删除? – Sajeetharan