gpt4 book ai didi

javascript - 如何使用 ng-repeat 访问驻留在函数和循环中的 json 数组?

转载 作者:行者123 更新时间:2023-12-01 01:43:53 25 4
gpt4 key购买 nike

我的 html 代码如下,用于评论页面:-

<div class="all_ques_back col-md-12" ng-init="result()" ng-repeat="ans in correctAns">
<div class="col-xs-1 col-md-1"><i class="fa fa-check-square fa-2x col_padd right_ans_font"></i></div>
<div class="col-xs-9 col-md-10 col_padd">
<div class="all_ques">hello your ans {{ans}}</div>
</div>
<div class="col-xs-1 col-md-1 col_padd"><i class="fa fa-angle-right right_arrow "></i></div>

我的 Controller 代码如下:-

var data = angular.module('App', ['ngRoute']);

data.controller('SmartLearnerController', function($scope, $location) {
$scope.result = function() {
$scope.correctAns = [{
"QuestionID": "1",
"QuestionLabel": "Why are mirrors often slightly curved (convex) ?",
"Image": "zibra-crossing.jpg",
"Correct": "two",
"Explaination": "Question one explaination is goes here"
}, {
"QuestionID": "2",
"QuestionLabel": "You are about to drive home. You feel very tired and have a severe headache. You should ?",
"Image": "",
"Correct": "one",
"Explaination": "Question two explaination is goes here"
}, {
"QuestionID": "3",
"QuestionLabel": "While you are driving on gra dient roads,you should ?",
"Image": "sign traffic.jpg",
"Correct": "one",
"Explaination": "Question three explaination is goes here"
}, {
"QuestionID": "4",
"QuestionLabel": "When child lock is applied in car ?",
"Image": "",
"Correct": "two",
"Explaination": "Question four explaination is goes here"
}]
$location.path("/reviewans");
}
});

最佳答案

请检查工作示例:DEMO

只需将 ng-init 移至上面的标签即可

<body ng-controller="MainCtrl"  ng-init="result()" >
<div class="all_ques_back col-md-12" ng-repeat="ans in correctAns">
<div class="col-xs-1 col-md-1"><i class="fa fa-check-square fa-2x col_padd right_ans_font"></i></div>
<div class="col-xs-9 col-md-10 col_padd">
<div class="all_ques">hello your ans {{ans}}</div>
</div>
<div class="col-xs-1 col-md-1 col_padd"><i class="fa fa-angle-right right_arrow "></i></div>
</div>

关于javascript - 如何使用 ng-repeat 访问驻留在函数和循环中的 json 数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31403922/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com