Skip to content

Instantly share code, notes, and snippets.

@khepin
Last active January 1, 2016 23:29
Show Gist options
  • Save khepin/8216893 to your computer and use it in GitHub Desktop.
Save khepin/8216893 to your computer and use it in GitHub Desktop.
/**
* This defines a simple widget
*/
function simpleWidget(){};
simpleWidget.$tags = [
{name: 'widget', value: {width: 1, height: 1}}
];
/**
* This defines a more complex one that depends on other services
*/
function complexWidget(serviceA) {};
simpleWidget.$inject = ['serviceA'];
simpleWidget.$tags = [
{name: 'widget', value: {width: 4, height: 2}},
//...
]
/**
* The widget manager receives ALL services that were tagged as "widgets"
*/
function widgetManager(widgets, $scope) {
// Here widgets would contain 'simpleWidget' and 'complexWidget'
for (var i = 0; i < widgets.length; i++) {
// Display the widget
}
}
widgetManager.$inject = ['$scope']
widgetManager.$inject.$tags = 'widget'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment