Skip to content

Instantly share code, notes, and snippets.

@goyalrohit
Created January 17, 2018 09:15
Show Gist options
  • Save goyalrohit/e46e7bd79dad50133c68513adffac31c to your computer and use it in GitHub Desktop.
Save goyalrohit/e46e7bd79dad50133c68513adffac31c to your computer and use it in GitHub Desktop.
Angular Factory Service
(function() {
angular.module('app')
.factory('dataService', dataService);
function dataService(logger) {
return {
getAllBooks: getAllBooks,
getAllReaders: getAllReaders
};
function getAllBooks() {
logger.output('getting all books');
return [
{
book_id: 1,
title: 'Harry Potter and the Deathly Hallows',
author: 'J.K. Rowling',
yearPublished: 2000
},
{
book_id: 2,
title: 'The Cat in the Hat',
author: 'Dr. Seuss',
yearPublished: 1957
},
{
book_id: 3,
title: 'Encyclopedia Brown, Boy Detective',
author: 'Donald J. Sobol',
yearPublished: 1963
}
];
}
function getAllReaders() {
logger.output('getting all readers');
return [
{
reader_id: 1,
name: 'Marie',
weeklyReadingGoal: 315,
totalMinutesRead: 5600
},
{
reader_id: 2,
name: 'Daniel',
weeklyReadingGoal: 210,
totalMinutesRead: 3000
},
{
reader_id: 3,
name: 'Lanier',
weeklyReadingGoal: 140,
totalMinutesRead: 600
}
];
}
}
dataService.$inject = ['logger'];
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment