ДМ
Size: a a a
ДМ
IF
Вキ
const service = await import(‘’).then(m => m.Service);
injector.get(service);
IF
const service = await import(‘’).then(m => m.Service);
injector.get(service);
Вキ
Вキ
IF
Вキ
IF
compileModuleAndAllComponentsAsync все само компильнетсяIF
S
IF

Вキ
// container.ts
// сервис, который позволяет регистрировать и резолвить сервисы
@Injectable({ providedIn: 'root' })
class Container {
link<T>(token: string, service: T): void;
resolve<T>(token: string): T;
}
// lazy.ts
// сервис, который регистрирует себя в контейнере
import { Container } from './container.ts';
@Injectable({ providedIn: 'root' })
class Service {
constructor(container: Container) {
// либо тут, и тогда надо зарезолвить сервис хотябы один раз
// либо где-то еще
container.link('token', this);
}
}
// component.ts
// компонент, который резолвит сервис из контейнера
import { Container } from './container.ts';
@Component({ … })
class Component {
constructor(contianer: Container) {
const service = container.resolve('token');
}
}
В
S

S
IF
IF
В
S