所以在简单的老Angular中,你会像这样注入一个工厂:
(function(angular){ "use strict"; var app = angular.module('app',[]); app.factory('MyFactory',['$http',function($http) { .... }); }());
现在使用Typescript,我试图像这样使用$inject:
module Services { export class MyFactory { static $inject = ['$http']; constructor(private $http: ng.IHttpService) { } } } var app = angular.module('app',[]); app.factory('MyFactory',Services.MyFactory) //<-- This does not work,never is instantiated. app.factory('MyFactory',Services.MyFactory]); //<-- No deal,it has constructor dependencies // Seems you have to do this app.factory('MyFactory',($http) => new Services.MyFactory($http)]);
使用Typescript在Angular中注入工厂的正确方法是什么?