UNPKG

ng-injector

Version:

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

33 lines 1.03 kB
'use strict'; var utils_1 = require('./utils'); exports.injector = function (deps) { if (deps === void 0) { deps = []; } if (typeof deps === 'string') { deps = [deps]; } else if (!(deps instanceof Array)) { throw new Error('deps must be Array'); } return function (target) { var construct = function (args) { var Component = function () { var _this = this; utils_1.forEach(args, function (arg, i) { return _this[deps[i]] = arg; }); return target.call(this); }; Component.prototype = target.prototype; return new Component(); }; var f = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i - 0] = arguments[_i]; } return construct(args); }; f.$inject = deps; f.prototype = target.prototype; return f; }; }; //# sourceMappingURL=injector.js.map