Created
June 10, 2017 19:45
-
-
Save anghelalexandra/a1578b1423b1019d5fe7a6058e507379 to your computer and use it in GitHub Desktop.
wp-pwa-sample-reading-and-validating-categories
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
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