Last active
August 14, 2017 06:13
-
-
Save lili21/b8677eacc5aa213e840dbe327f3b776c to your computer and use it in GitHub Desktop.
decorator-ng-di
This file contains hidden or 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
@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