UNPKG

ohayolibs

Version:

Ohayo is a set of essential modules for ohayojp.

19 lines (17 loc) 776 B
import { ApplicationRef, NgModuleRef } from '@angular/core'; import { createNewHosts } from '@angularclass/hmr'; import { NzModalService } from 'ng-zorro-antd/modal'; export const hmrBootstrap = (module: any, bootstrap: () => Promise<NgModuleRef<any>>) => { let ngModule: NgModuleRef<any>; module.hot.accept(); bootstrap().then(mod => (ngModule = mod)); module.hot.dispose(() => { const appRef: ApplicationRef = ngModule.injector.get(ApplicationRef); const modalService = ngModule.injector.get(NzModalService, null) as NzModalService; if (modalService) modalService.closeAll(); const elements = appRef.components.map(c => c.location.nativeElement); const makeVisible = createNewHosts(elements); ngModule.destroy(); makeVisible(); }); };