-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlazy-load-modal.component.ts
38 lines (33 loc) · 1.09 KB
/
lazy-load-modal.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import {
Component,
ComponentFactory,
NgModuleFactory,
NgModuleFactoryLoader,
ViewContainerRef,
} from "@angular/core";
import { NSModuleFactoryLoader } from "nativescript-angular/router";
import { ModalDialogService } from "nativescript-angular/directives/dialogs";
import { LazyComponent } from "../../lazy/lazy.component";
@Component({
template: `
<Button text="Load modal!" (tap)="openModal()"></Button>
`
})
export class LazyLoadModalComponent {
constructor(
private moduleLoader: NgModuleFactoryLoader,
private vcRef: ViewContainerRef,
private modalService: ModalDialogService
) { }
public openModal() {
this.moduleLoader.load("./lazy/lazy.module#LazyModule")
.then((module: NgModuleFactory<any>) => {
const moduleRef = module.create(this.vcRef.parentInjector);
this.modalService.showModal(LazyComponent, {
moduleRef,
viewContainerRef: this.vcRef,
context: { isModal: true }
});
});
}
}