Angularjs 带Angular2注入器的TypeScript泛型
我试着用一个注入器在角度上使用依赖注入。我希望能够在运行时根据该组件发送的内容实例化类型Angularjs 带Angular2注入器的TypeScript泛型,angularjs,typescript,code-injection,typescript-typings,typescript-generics,Angularjs,Typescript,Code Injection,Typescript Typings,Typescript Generics,我试着用一个注入器在角度上使用依赖注入。我希望能够在运行时根据该组件发送的内容实例化类型 @Injectable() export class ServiceInjectionManager { private _injector: ReflectiveInjector; constructor() { this._injector = ReflectiveInjector.resolveAndCreate([ MockBackend,
@Injectable()
export class ServiceInjectionManager {
private _injector: ReflectiveInjector;
constructor() {
this._injector = ReflectiveInjector.resolveAndCreate([
MockBackend,
BaseRequestOptions,
{
provide: Http,
useFactory: (backendInstance: MockBackend, defaultOptions: BaseRequestOptions) => {
return new Http(backendInstance, defaultOptions);
},
deps: [MockBackend, BaseRequestOptions]
},
AppSettings,
HierarchyService
]);
}
public resolve<T extends HierarchyService>(type:any): T {
return this._injector.get(type);
}
}
@Injectable()
导出类ServiceInjectionManager{
专用注射器:反射式注射器;
构造函数(){
此._injector=ReflectiveInjector.resolveAndCreate([
模拟后端,
BaseRequestOptions,
{
提供:Http,
useFactory:(backendInstance:MockBackend,defaultOptions:BaseRequestOptions)=>{
返回新的Http(backendInstance,defaultOptions);
},
deps:[MockBackend,BaseRequestOptions]
},
应用程序设置,
等级服务
]);
}
公共解析(类型:any):T{
返回此。\u喷油器。获取(类型);
}
}
我似乎找不到通过打字的方法。我采取了多种方法,包括:
public resolve<T extends HierarchyService>(T): T {
return this._injector.get(T);
}
公共解析(T):T{
返回此项。\u喷油器。获取(T);
}
TypeScript中的泛型似乎与.NET中的不同