我正在學習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