I have a post function that gets my json.
I want to print out all the
max_slots
, base_image
and c_name
as they are in a array I am trying to loop though save value to scope to use in my HTML.
Am I doing this right ? if not whats the best way to do this ?
OBJECTIVE
display the results of the json array post in my html
What I am trying
$scope.c_name = [0]; $scope.GetData = function () { $http({ url: "http://www.ccuktech.co.uk/ccuploader/campaigns/getCampaign", method: "POST", date: {}, headers: {'Content-Type': 'application/json'} }).then(function (data) { // success console.log('you have received the data '); console.log(data); // $scope.base_image = response.base_image; $scope.c_name = response.c_name; $scope.c_name = data.data.c_name; // for(var i = 0; i < c_name.length; i++) { // var obj = c_name[i]; // // console.log(obj.id); // } // $scope.max_slots = data.data.max_slots; // $scope.slot_image = data.slots.base_image; // console.log($scope.c_name); }, function (response) { // failed console.log('failed getting campaigns goo back to log in page.'); console.log(response); }); };
My HTML
<body ng-app='myApp'> <h2>name</h2>: {{c_name}} <h2>max slots</h2>: {{max_slots}} <h2>image</h2>: {{base_image}} </body>
JavaScript
$scope.GetData = function () { $http({ url: "http://www.####.co.uk/####/####/####", method: "POST", date: {}, headers: {'Content-Type': 'application/json'} }).then(function (data) { // success console.log('you have received the data '); console.log(data); // $scope.base_image = response.base_image; $scope.c_name = response.c_name; // $scope.c_name = data.data.c_name; for(var i = 0; i < c_name.length; i++) { var obj = c_name[i]; console.log(obj.id); } // $scope.max_slots = data.data.max_slots; // $scope.slot_image = data.slots.base_image; // console.log($scope.c_name); }, function (response) { // failed console.log('failed getting campaigns goo back to log in page.'); console.log(response); }); }; $scope.GetData();
console.log(data) result
data[0].max_slots
,data[0].c_name
anddata[0].slots[0].base_image
data.data[0].max_slots
?