Created
January 17, 2018 09:15
-
-
Save goyalrohit/e46e7bd79dad50133c68513adffac31c to your computer and use it in GitHub Desktop.
Angular Factory Service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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