Skip to content

Commit cdf0e88

Browse files
committed
fixed load bundles
1 parent f255801 commit cdf0e88

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

ng2ts/main.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ import { ApplicationRef, enableProdMode, NgModuleRef } from '@angular/core';
55
import { ResourceLoader } from '@angular/compiler';
66
import * as code from './code';
77

8-
/* dark magic, please ignore */ try {enableProdMode();} catch (e) {} /* The code below is used to match the Components with the appropriate templates. */class MyResourceLoader extends ResourceLoader {get(url: string): Promise<string> { let searchString = url.replace(/[\/\.-]/gi, '_');
8+
// /* dark magic, please ignore */ try {enableProdMode();} catch (e) {} /* The code below is used to match the Components with the appropriate templates. */
9+
class MyResourceLoader extends ResourceLoader {get(url: string): Promise<string> { let searchString = url.replace(/[\/\.-]/gi, '_');
910

1011
// TODO(sancheez): fix load templates with relative url (relative url in Component)
11-
if (url.startsWith(".")) {searchString = searchString.substring(2);}const templateId = Object.keys(code).find((key) => key.includes(searchString));let template = code[templateId];if (!template) {console.log(template);debugger;}return Promise.resolve(template);};}function createNewHosts(cmps) {const components = Array.prototype.map.call(cmps, function (componentNode) {const newNode = document.createElement(componentNode.tagName);if (!componentNode.parentNode) {document.body.append(componentNode);}const parentNode = componentNode.parentNode;const currentDisplay = newNode.style.display;newNode.style.display = 'none';parentNode.insertBefore(newNode, componentNode);function removeOldHost() {newNode.style.display = currentDisplay;try {parentNode.removeChild(componentNode);} catch (e) {}}return removeOldHost;});return function removeOldHosts() {components.forEach(function (removeOldHost) {return removeOldHost();});};}export const hmrBootstrap = (ngModule: NgModuleRef<any>) => {const appRef: ApplicationRef = ngModule.injector.get(ApplicationRef);const elements = appRef.components.map((c) => c.location.nativeElement);const makeVisible = createNewHosts(elements);ngModule.destroy();makeVisible();};if (window['ref']) {hmrBootstrap(window['ref']);window['ref'] = null;}
12+
if (url.startsWith(".")) {
13+
searchString = searchString.substring(2);
14+
}
15+
16+
const templateId = Object.keys(code).find((key) => key.includes(searchString));let template = code[templateId];if (!template) {console.log(template);debugger;}return Promise.resolve(template);};}function createNewHosts(cmps) {const components = Array.prototype.map.call(cmps, function (componentNode) {const newNode = document.createElement(componentNode.tagName);if (!componentNode.parentNode) {document.body.append(componentNode);}const parentNode = componentNode.parentNode;const currentDisplay = newNode.style.display;newNode.style.display = 'none';parentNode.insertBefore(newNode, componentNode);function removeOldHost() {newNode.style.display = currentDisplay;try {parentNode.removeChild(componentNode);} catch (e) {}}return removeOldHost;});return function removeOldHosts() {components.forEach(function (removeOldHost) {return removeOldHost();});};}export const hmrBootstrap = (ngModule: NgModuleRef<any>) => {const appRef: ApplicationRef = ngModule.injector.get(ApplicationRef);const elements = appRef.components.map((c) => c.location.nativeElement);const makeVisible = createNewHosts(elements);ngModule.destroy();makeVisible();};if (window['ref']) {hmrBootstrap(window['ref']);window['ref'] = null;}
1217

1318
/*/d*//*d:bootstrapSolved/trimTrailing*/
1419
const platform = platformBrowserDynamic();

0 commit comments

Comments
 (0)