I'm having trouble displaying data in a table format.
The issue arises when I try to fetch data from a JSON file using a custom service. The fetched data is then inserted into the $rootScope object.
However, when I preview the view, it appears blank without any errors. Below is the line of code used to iterate through the array of objects named "books" in the view:
Please provide guidance on this matter.
controller.js
Controllers.controller('BookListCtrl_Student', ['$scope','$rootScope','$http','$location','BookData',
function ($scope, $rootScope, $http, $location, BookData) {
$rootScope.books=[];
$rootScope.books.push(BookData.getData());
$scope.bookLists = ['All Books', 'Available Books'];
$scope.selection = $scope.bookLists[0];
$scope.backToLogin = function() {
$location.path("/main");
}
}
]);
customservice.js
Controllers.factory('BookData',['$http',function(http){
return {
getData: function() {
return http.get('data/books.json').then(function(result){
return result.data;
});
}
};
}
]);