javascript - How to access json array resides in function and loop with ng-repeat? -
my html code below reviewans page :-
<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 ans {{ans}}</div> </div> <div class="col-xs-1 col-md-1 col_padd"><i class="fa fa-angle-right right_arrow "></i></div>
and controller code :-
var data = angular.module('app', ['ngroute']); data.controller('smartlearnercontroller', function($scope, $location) { $scope.result = function() { $scope.correctans = [{ "questionid": "1", "questionlabel": "why mirrors curved (convex) ?", "image": "zibra-crossing.jpg", "correct": "two", "explaination": "question 1 explaination goes here" }, { "questionid": "2", "questionlabel": "you drive home. feel tired , have severe headache. should ?", "image": "", "correct": "one", "explaination": "question 2 explaination goes here" }, { "questionid": "3", "questionlabel": "while driving on gra dient roads,you should ?", "image": "sign traffic.jpg", "correct": "one", "explaination": "question 3 explaination goes here" }, { "questionid": "4", "questionlabel": "when child lock applied in car ?", "image": "", "correct": "two", "explaination": "question 4 explaination goes here" }] $location.path("/reviewans"); } });
please check working example : demo
just move ng-init above tag
i.e
<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 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>
Comments
Post a Comment