Encountering an issue with a lazy loaded list of books. Initially, 10 books are loaded and if the user scrolls down, the next 10 books are loaded.
For example, if the user is on "page" 4 and clicks on the 35th book to view details, upon returning to the list, only the first 10 books are visible again, requiring all lazy loadings to be redone.
Is there any way to implement caching or storing to prevent this from happening? Thank you for any suggestions!
[UPDATE] Thanks for your replies!
routes
.state('app.books.list',{
...
...
resolve: {
books : function(bookFactoryBook) {
return booksFactoryBook.getList({page : 1});
}
}
})
.state('app.books.details',{
// just loads detail
})
ctrl (controller as syntax)
function bookControllerList(_books, ....) {
vm = this;
vm.books = _books;
......
// lazy loader just appends new data on vm.books
// after loading was successful
/**
* init lazy loader
*
* @desc initialize lazy-loader for books
* @return {void}
* @private
*/
function _initLazyLoader() {
if(_isLazyLoadingEnabled() === false) {
return;
}
// configure lazy loader
var mapper = {
data : 'books', // vm.books
isEnabled : 'lazyLoadingEnabled',
indicatorId : 'lazyLoadingIndicatorId',
onDataLoaded : _afterLazyLoading
};
if(booksFactoryLazyLoader.setup(vm, mapper) === false) {
// failed to initialize lazy loader - disable feature
vm.lazyLoadingEnabled = false;
} else {
vm.lazyLoadingEnabled = true;
}
}
/**
* after lazy loading
*
* @desc manages data manipulation after lazy loading
* @param books - {Array} - new loaded data to manipulate
* @return {void}
* @private
*/
function _afterLazyLoading(books) {
// check if user is logged in
if(authFactorySession.isAuthorized() === true) {
// try to flag favorites in received books
books = _addFavoriteFlags(books);
}
// append data to vm
vm.books = vm.books.concat(books);
}
}
Could it be an issue with the controller as syntax? How can I extend the lifetime of my scope / vm object?
If I change the order of the states and connect them as parent / child (app.books.list and app.books.list.detail), it doesn't make any difference.
Thank you for any insights