v0.0.16 Course Detail, caching engine - zhentian-wan/MEANAppsFiles GitHub Wiki
#Caching
There are two cases:
- User visits the main page first (which contains all courses), then from main page to a course detail page.
- User visits a course detail directly without visiting main page.
Two different cases can use one caching engine to handle:
Still use our CourseCachedService
, it checks whether the courses have been downloaded from the server. We use CourseCachedService to get all the course, then we get one course detail from the courses array. If there is no courses array, we get all courses first.
function CourseDetailController($routeParams, CourseCachedService) {
var vm = this;
vm.course = {};
CourseCachedService.query().$promise.then(function(courses) {
vm.course = _.find(courses, {'_id': $routeParams.id});
})
}
angular.module('app')
.controller('CourseDetailController', CourseDetailController);