Last active
August 29, 2015 14:07
-
-
Save Tzrlk/3cca5404ab5f268e90f7 to your computer and use it in GitHub Desktop.
Angular injection adapter
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
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; | |
} |
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
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