Skip to content

Instantly share code, notes, and snippets.

@anghelalexandra
Created June 10, 2017 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anghelalexandra/a1578b1423b1019d5fe7a6058e507379 to your computer and use it in GitHub Desktop.
Save anghelalexandra/a1578b1423b1019d5fe7a6058e507379 to your computer and use it in GitHub Desktop.
wp-pwa-sample-reading-and-validating-categories
class Categories {
constructor($log, $q, AppticlesAPI, AppticlesValidation) {
const validateCategories = (result) => {
let validatedCategories = AppticlesValidation.validateCategories(result);
return $q.when(validatedCategories);
};
const populateCategories = (result) => {
if (angular.isUndefined(result.error)) {
this.categories = result;
}
};
AppticlesAPI.findCategories({hide_empty: 1})
.then(validateCategories)
.then(populateCategories)
.catch($log.error);
}
}
Categories.$inject = ['$log', '$q', 'AppticlesAPI', 'AppticlesValidation'];
angular.module('appticles.categories')
.controller('CategoriesController', Categories);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment