javascript - interate through nested json file using ng-repeat not working -
so have json file nested elements. json file:
[ { "qid": "1", "contester": "0", "answer": "0", "question": "what after getting argument? ", "images": [ { "qid": "1", "imageid": "ab100", "imgname": "doghug_q1", "imgpath": "images\/q1\/doghug_q1.jpg" }, { "qid": "1", "imageid": "ab101", "imgname": "eq_q1.jpg", "imgpath": "images\/q1\/eat_q1.jpg" }, { "qid": "1", "imageid": "ab102", "imgname": "headache_q1", "imgpath": "images\/q1\/headache_q1.jpg" }, { "qid": "1", "imageid": "ab106", "imgname": "scream_q1.jpg", "imgpath": "images\/q1\/scream_q1.jpg" }, { "qid": "1", "imageid": "ab107", "imgname": "shopping_q1", "imgpath": "images\/q1\/shopping_q1.jpg" }, { "qid": "1", "imageid": "ab108", "imgname": "walkalone_q1", "imgpath": "images\/q1\/walkalone_q1.jpg" } ] }, { "qid": "2", "contester": "0", "answer": "0", "question": "which game rather play?", "images": [ { "qid": "2", "imageid": "ab105", "imgname": "charades_q2.jpg", "imgpath": "images\/q2\/charades_q2.jpg" }, { "qid": "2", "imageid": "ab109", "imgname": "playingcards_q2.jpg", "imgpath": "images\/q2\/playingcards_q2.jpg" }, { "qid": "2", "imageid": "ab110", "imgname": "chess_q2", "imgpath": "images\/q2\/chess_q2.jpg" }, { "qid": "2", "imageid": "ab111", "imgname": "twister_q2", "imgpath": "images\/q2\/twister_q2.jpg" } ] }
]
and controller used access json :
var app= angular.module('myapp', []); app.controller('listctrl', ['$scope', '$http', function($scope, $http) { $http.get('results.json').success(function(data) { $scope.questions = data; // data json angular.foreach($scope.questions, function(item){ console.log(item.images); }) }); }); } ]);
and html code display questions , each questions list of images using ng-repeat :
<body ng-app="myapp" > <div ng-controller="listctrl"> <ul> <li ng-repeat="question in questions"> {{question.qid}} </li> </ul> </div> </body>
as of iam trying display questions id json file list output im getting a:
- {{question.qid}}
as output in html page.. can please me. dont know im doing wrong.
your code has missing things.
here working example of code
http://plnkr.co/edit/fvd26tyz9v8tbgubuzn2?p=preview
firstly,
var app = angular.module('myapp', []); //variable app missing.
secondly, data mention has missing closing square brace.
Comments
Post a Comment