Basically my angular code looks like this
var myapp = angular.module("Demo",["ngRoute"])
.config(function($routeProvider){
$routeProvider
.when("/students",{
templateUrl : "templates/students.html",
controller : "grouplistcontroller"
})
})
.controller("grouplistcontroller", function($scope,$http){
$http.get("ajaxfunction.php?action=getlist")
.then(function(res) {
var obj = JSON.stringify(res);
console.log(obj);
$scope.students = obj.data;
});
});
The json data from server looks like this
"data":[
{
"sub_id":"1199",
"sub_group":"GT"
},
{
"sub_id":"727",
"sub_group":"GT"
},
{
"sub_id":"660",
"sub_group":"GT"
},
{
"sub_id":"614",
"sub_group":"GT"
}
],
"status":200,
"config":{
"method":"GET",
"transformRequest":[
null
],
"transformResponse":[
null
],
"url":"ajaxfunction.php?action=getlist",
"headers":{
"Accept":"application/json, text/plain, */*"
}
},
"statusText":"OK"
I am trying to display the loop from the result in my front end, which isnt working
<ul>
<li ng-repeat="student in students">
{{ student.sub_id }}
</li>
</ul>
$scope.students = res.data, notobj.data.objis your JSON string and it has nodataproperty. See plnkr.co/edit/8KMvL0CX6Bry3oBNdHct?p=preview