【发布时间】:2016-01-18 00:38:49
【问题描述】:
我想使用工厂来管理我的一些依赖注入,因此我在函数内部创建了一个本地类。我使用的 JavaScript 框架(AngularJS)会将函数的返回值注入到构造函数中。
如何从工厂函数外部引用返回的类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 类上的所有方法维护接口。
【问题讨论】:
标签: angularjs typescript ecmascript-6