Skip to content

Instantly share code, notes, and snippets.

@jamsesso
Last active March 27, 2016 17:26
Show Gist options
  • Save jamsesso/830ecaaa78654d5fc71c to your computer and use it in GitHub Desktop.
Save jamsesso/830ecaaa78654d5fc71c to your computer and use it in GitHub Desktop.
ES6 Directives in AngularJS - Registering services
import * as services from './module';
const serviceModule = angular.module('app.services', []);
// Automatically register each service.
Object.keys(services).forEach(key => {
if(!services[key].__service) {
console.warn(`Service ${key} is missing the @Service decorator.`);
return;
}
const { name } = services[key].__service;
const defaultName = key.substring(0, 1).toLowerCase() + key.substring(1);
serviceModule.service(name || defaultName, services[key]);
});
export default serviceModule.name;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment