UNPKG

1.64 kBJavaScriptView Raw
1import { Compiler, Injectable } from '@angular/core';
2/**
3 * NgModuleFactoryLoader that uses SystemJS to load NgModuleFactory
4 */
5var NgModuleLoader = (function () {
6 function NgModuleLoader(_compiler) {
7 this._compiler = _compiler;
8 }
9 NgModuleLoader.prototype.load = function (modulePath, ngModuleExport) {
10 var offlineMode = this._compiler instanceof Compiler;
11 return offlineMode ? loadPrecompiledFactory(modulePath, ngModuleExport) : loadAndCompile(this._compiler, modulePath, ngModuleExport);
12 };
13 NgModuleLoader.decorators = [
14 { type: Injectable },
15 ];
16 /** @nocollapse */
17 NgModuleLoader.ctorParameters = function () { return [
18 { type: Compiler, },
19 ]; };
20 return NgModuleLoader;
21}());
22export { NgModuleLoader };
23function loadAndCompile(compiler, modulePath, ngModuleExport) {
24 if (!ngModuleExport) {
25 ngModuleExport = 'default';
26 }
27 return System.import(modulePath)
28 .then(function (rawModule) {
29 var module = rawModule[ngModuleExport];
30 if (!module) {
31 throw new Error("Module " + modulePath + " does not export " + ngModuleExport);
32 }
33 return compiler.compileModuleAsync(module);
34 });
35}
36function loadPrecompiledFactory(modulePath, ngModuleExport) {
37 return System.import(modulePath)
38 .then(function (rawModule) {
39 var ngModuleFactory = rawModule[ngModuleExport];
40 if (!ngModuleFactory) {
41 throw new Error("Module " + modulePath + " does not export " + ngModuleExport);
42 }
43 return ngModuleFactory;
44 });
45}
46//# sourceMappingURL=ng-module-loader.js.map
\No newline at end of file