I am working on a project where I need to fetch data from API and display it on HTML page using Angularjs
API is returning me the Categories details. Here is my API
http://naazexpress.com/category.php
this is my angularjs Code
var app = angular.module('appControllers', [])
app.controller('ProductCtrl', function($scope, srvShareData,$http) {
// alert('product Controller');
$http.get("http://naazexpress.com/category.php")
.then(function (response) {
$scope.data = response.data.children;
console.log(response);
});
console.log('aa');
// alert($scope.data);
$scope.sharedData = srvShareData.getData();
console.log($scope.sharedData);
});
app.service('srvShareData', function($window) {
var KEY = 'App.SelectedValue';
// alert('ssss');
var addData = function(newObj) {
var mydata = $window.sessionStorage.getItem(KEY);
console.log(mydata);
if (mydata) {
mydata = JSON.parse(mydata);
} else {
mydata = [];
}
mydata = newObj;
console.log(mydata);
// mydata.push(newObj);
$window.sessionStorage.setItem(KEY, JSON.stringify(mydata));
};
var getData = function(){
var mydata = $window.sessionStorage.getItem(KEY);
if (mydata) {
mydata = JSON.parse(mydata);
}
return mydata || [];
};
return {
addData: addData,
getData: getData
};
});
and I am implementing it in my HTML page
here is my HTML page
<div id="login-page" class="row" ng-app="starter">
<div class="col s12 z-depth-6 card-panel">
<form class="login-form" id="login">
<div class="row">
<div class="input-field col s12 center">
<img src="http://naazexpress.com/skin/frontend/default/jm_casual/images/logo.png" alt="" class="responsive-img valign profile-image-login">
<p class="center login-form-text">Seller - NaazExpress</p>
</div>
</div>
<div class="input-field col s12 m6" ng-controller="ProductCtrl">
<ul ng-repeat="item in data">
<li>{{item.name}}</li>
</ul></div>
</div></div>
when i run this program the API is not returning anything. is there any issue in the code ? please help
console.log(response)
?console.log(response)
response.data