我想用工厂来管理我的一些依赖注入,所以我在函数内部创建了一个本地类。我使用的JavaScript框架(AngularJS)会将函数的返回值注入到构造函数中。在工厂函数外部公开类型的本地TypeScript类
如何从工厂函数外引用返回类Record
的类型?
/** Define factory to create Record classes */
export default function RecordFactory($window) {
return class Record { // I want to reference this class as a type
doSomething() {
// use $window service
}
}
}
/**
* Controller for page with returned class of RecordFactory injected
* into the constructor
*/
class RecordPageCtrl {
record
constructor(Record) { // How do I specify the type of Record here?
this.record = new Record();
}
}
// Dependency Injection is handled by AngularJS
angular.module('myApp', [])
.factory('Record', RecordFactory)
.controller('RecordPageCtrl', RecordPageCtrl)
注:我试图避免与维护上的所有Record
类的方法的接口。
谢谢你的回应。但是,我不能重现这一点。我无法从Record类中访问注入的服务(例如'$ window')。 – Chic