UNPKG

ng-injector

Version:

Injector decorator for writing angular 1.x with ES6/TypeScript

27 lines 798 B
'use strict'; import { forEach } from './utils'; export const injector = (deps = []) => { if (typeof deps === 'string') { deps = [deps]; } else if (!(deps instanceof Array)) { throw new Error('deps must be Array'); } return (target) => { const construct = function (args) { const Component = function () { forEach(args, (arg, i) => this[deps[i]] = arg); return target.call(this); }; Component.prototype = target.prototype; return new Component(); }; const f = function (...args) { return construct(args); }; f.$inject = deps; f.prototype = target.prototype; return f; }; }; //# sourceMappingURL=injector.js.map