UNPKG

2.25 kBJavaScriptView Raw
1import { Compiler, Injectable } from '@angular/core';
2/**
3 * NgModuleFactoryLoader that uses SystemJS to load NgModuleFactory
4 */
5var NgModuleLoader = (function () {
6 /**
7 * @param {?} _compiler
8 */
9 function NgModuleLoader(_compiler) {
10 this._compiler = _compiler;
11 }
12 /**
13 * @param {?} modulePath
14 * @param {?} ngModuleExport
15 * @return {?}
16 */
17 NgModuleLoader.prototype.load = function (modulePath, ngModuleExport) {
18 var /** @type {?} */ offlineMode = this._compiler instanceof Compiler;
19 return offlineMode ? loadPrecompiledFactory(modulePath, ngModuleExport) : loadAndCompile(this._compiler, modulePath, ngModuleExport);
20 };
21 return NgModuleLoader;
22}());
23export { NgModuleLoader };
24NgModuleLoader.decorators = [
25 { type: Injectable },
26];
27/**
28 * @nocollapse
29 */
30NgModuleLoader.ctorParameters = function () { return [
31 { type: Compiler, },
32]; };
33function NgModuleLoader_tsickle_Closure_declarations() {
34 /** @type {?} */
35 NgModuleLoader.decorators;
36 /**
37 * @nocollapse
38 * @type {?}
39 */
40 NgModuleLoader.ctorParameters;
41 /** @type {?} */
42 NgModuleLoader.prototype._compiler;
43}
44/**
45 * @param {?} compiler
46 * @param {?} modulePath
47 * @param {?} ngModuleExport
48 * @return {?}
49 */
50function loadAndCompile(compiler, modulePath, ngModuleExport) {
51 if (!ngModuleExport) {
52 ngModuleExport = 'default';
53 }
54 return System.import(modulePath)
55 .then(function (rawModule) {
56 var /** @type {?} */ module = rawModule[ngModuleExport];
57 if (!module) {
58 throw new Error("Module " + modulePath + " does not export " + ngModuleExport);
59 }
60 return compiler.compileModuleAsync(module);
61 });
62}
63/**
64 * @param {?} modulePath
65 * @param {?} ngModuleExport
66 * @return {?}
67 */
68function loadPrecompiledFactory(modulePath, ngModuleExport) {
69 return System.import(modulePath)
70 .then(function (rawModule) {
71 var /** @type {?} */ ngModuleFactory = rawModule[ngModuleExport];
72 if (!ngModuleFactory) {
73 throw new Error("Module " + modulePath + " does not export " + ngModuleExport);
74 }
75 return ngModuleFactory;
76 });
77}
78//# sourceMappingURL=ng-module-loader.js.map
\No newline at end of file