Skip to content

Instantly share code, notes, and snippets.

@lili21
Last active August 14, 2017 06:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lili21/b8677eacc5aa213e840dbe327f3b776c to your computer and use it in GitHub Desktop.
Save lili21/b8677eacc5aa213e840dbe327f3b776c to your computer and use it in GitHub Desktop.
decorator-ng-di
@Inject('ServiceA', 'ServiceB', 'ServiceC')
class Ctrl {
fetchData () {
this.ServiceA.fetch()
}
}
function Inject (...args) {
return function (target, key, descriptor) {
const ctrl = function (..._args) {
args.forEach((v, i) => {
this[v] = _args[i]
})
return target.apply(this, _args)
}
ctrl.prototype = target.prototype
ctrl.$inject = args
return ctrl
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment