我需要在运行时动态加载类,例如psuedocode:
@Injectable()
export class MyService {
withGettable(serviceName: IGettableServices) {
return @Inject(serviceName)service.get()
}
}
我该怎么做?
答案 0 :(得分:2)
在页面底部的injector中查看一些示例。
@Injectable()
export class MyService {
constructor(private injector: Injector) {}
withGettable(serviceName: IGettableServices) {
// retrieves an instance from the injector based on the provided token.
return this.injector.get(serviceName);
}
}