Skip to content

Instantly share code, notes, and snippets.

@Tzrlk
Last active August 29, 2015 14:07
Show Gist options
  • Save Tzrlk/3cca5404ab5f268e90f7 to your computer and use it in GitHub Desktop.
Save Tzrlk/3cca5404ab5f268e90f7 to your computer and use it in GitHub Desktop.
Angular injection adapter
function inject(deps, target) {
var list = _.keys(deps);
list.push(function() {
var context = arguments;
var resolved = {};
_.each(list, function(value, index) {
resolved[deps[value]] = context[index];
});
target.call(resolved);
});
return list;
}
angular.module('module').service('service', inject({
$scope: 'scope',
$state: 'state',
$localStorage: 'storage'
}, function() {
var $this = this;
_.extend($this.scope, {
storage: $this.storage;
nav: function($event) {
$event && $event.preventDefault();
$this.state.go('somewhere');
}
});
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment