1
- import { ComponentFactory , ComponentRef , Injectable , Injector , NgModuleFactoryLoader } from "@angular/core" ;
1
+ import { Compiler , ComponentFactory , ComponentRef , Injectable , Injector , ViewContainerRef } from "@angular/core" ;
2
2
3
- import { DBVIEW_MODULE_ENTRY_COMPONENT_TOKEN , DbViewEntryComponentInterface } from "src/web/browser-window/app/app.constants" ;
3
+ import { DBVIEW_MODULE_ENTRY_COMPONENT_TOKEN } from "src/web/browser-window/app/app.constants" ;
4
4
import { DbAccountPk } from "src/shared/model/database" ;
5
5
6
+ type DbViewEntryComponent = import ( "src/web/browser-window/app/_db-view/db-view-entry.component" ) . DbViewEntryComponent ;
7
+
6
8
@Injectable ( )
7
9
export class DbViewModuleResolve {
8
10
9
11
private state : {
10
- resolveComponentFactory : ( ) => Promise < ComponentFactory < DbViewEntryComponentInterface > > ;
12
+ resolveComponentFactory : ( ) => Promise < ComponentFactory < DbViewEntryComponent > > ;
11
13
} = {
12
14
resolveComponentFactory : async ( ) => {
13
- const moduleFactory = await this . moduleLoader . load ( "./_db-view/db-view.module#DbViewModule" ) ;
15
+ const { DbViewModule} = await import ( "src/web/browser-window/app/_db-view/db-view.module" ) ;
16
+ const compiler = this . injector . get ( Compiler ) ;
17
+ const moduleFactory = await compiler . compileModuleAsync ( DbViewModule ) ;
14
18
const moduleRef = moduleFactory . create ( this . injector ) ;
15
19
const component = moduleRef . injector . get ( DBVIEW_MODULE_ENTRY_COMPONENT_TOKEN ) ;
16
20
const componentFactory = moduleRef . componentFactoryResolver . resolveComponentFactory ( component ) ;
@@ -23,15 +27,18 @@ export class DbViewModuleResolve {
23
27
} ;
24
28
25
29
constructor (
26
- private moduleLoader : NgModuleFactoryLoader ,
27
30
private injector : Injector ,
28
31
) { }
29
32
30
- async buildComponentRef ( dbAccountPk : DbAccountPk ) : Promise < ComponentRef < DbViewEntryComponentInterface > > {
33
+ async mountDbViewEntryComponent (
34
+ container : ViewContainerRef ,
35
+ dbAccountPk : DbAccountPk ,
36
+ ) : Promise < ComponentRef < DbViewEntryComponent > > {
31
37
const componentFactory = await this . state . resolveComponentFactory ( ) ;
32
- const componentRef = componentFactory . create ( this . injector ) ;
38
+ const componentRef = container . createComponent ( componentFactory ) ;
33
39
34
40
componentRef . instance . dbAccountPk = dbAccountPk ;
41
+ componentRef . changeDetectorRef . detectChanges ( ) ;
35
42
36
43
return componentRef ;
37
44
}
0 commit comments