Angular 你能在运行时@Inject吗?
我需要在运行时动态加载一个类,如以下psuedocode:Angular 你能在运行时@Inject吗?,angular,Angular,我需要在运行时动态加载一个类,如以下psuedocode: @Injectable() export class MyService { withGettable(serviceName: IGettableServices) { return @Inject(serviceName)service.get() } } 我该怎么做呢?看看页面底部的一些例子 @Injectable() 导出类MyService{ 构造函数(专用注入器:注入器){} withGettable(服务
@Injectable()
export class MyService {
withGettable(serviceName: IGettableServices) {
return @Inject(serviceName)service.get()
}
}
我该怎么做呢?看看页面底部的一些例子
@Injectable()
导出类MyService{
构造函数(专用注入器:注入器){}
withGettable(服务名称:IGettableServices){
//根据提供的令牌从注入器检索实例。
返回此.injector.get(serviceName);
}
}