import {NgModuleFactoryLoader} from '@angular/core';
import {AsyncNgModuleLoader} from './async-ng-module-loader';
// Add to main providers
{provide: NgModuleFactoryLoader, useClass: AsyncNgModuleLoader}
-
-
Save brandonroberts/02cc07face25886fe142c4dbd8da1340 to your computer and use it in GitHub Desktop.
import {Injectable, NgModuleFactory, NgModuleFactoryLoader, Compiler, Type} from '@angular/core'; | |
class LoaderCallback { | |
constructor(public callback) {} | |
} | |
export let load: Type = (callback: Function) => { | |
return new LoaderCallback(callback); | |
}; | |
/** | |
* NgModuleFactoryLoader that uses Promise to load NgModule type and then compiles them. | |
* @experimental | |
*/ | |
@Injectable() | |
export class AsyncNgModuleLoader implements NgModuleFactoryLoader { | |
constructor(private compiler: Compiler) {} | |
load(modulePath: string|LoaderCallback): Promise<NgModuleFactory<any>> { | |
if (modulePath instanceof LoaderCallback) { | |
let loader = (modulePath as LoaderCallback).callback(); | |
return Promise | |
.resolve(loader) | |
.then((type: any) => checkNotEmpty(type, '', '')) | |
.then((type: any) => this.compiler.compileModuleAsync(type)); | |
} | |
return Promise.resolve(null); | |
} | |
} | |
function checkNotEmpty(value: any, modulePath: string, exportName: string): any { | |
if (!value) { | |
throw new Error(`Cannot find '${exportName}' in '${modulePath}'`); | |
} | |
return value; | |
} |
the same issue with @lialosiu
@qk44077907 @lialosiu are you still having this issue? With RC6 you don't need a custom loader anymore. I also have a webpack loader here you can use if you want to use string-based lazy loading: https://www.npmjs.com/package/angular2-router-loader
hello can anyone help me,
Work this issue with RC5.
{
path: 'admin',
loadChildren: load(() => new Promise(resolve => {
return (require as any).ensure([], (require: any) => {
return resolve(require('./pages/dev/dev.module').default);
});
}))
},
because of require cannot find name.
export let load: Type = (callback: Function) => {
return new LoaderCallback(callback);
};
Generic type 'Type' requires 1 type argument(s)
Getting above error while compile with ng serve
node -v 7.0.0
npm -v 3.10.8
angular-cli: 1.0.0-beta.19-3
editor : Visual Studio Code
please help me...
"dependencies": {
"@angular/common": "~2.1.0",
"@angular/compiler": "~2.1.0",
"@angular/core": "~2.1.0",
"@angular/forms": "~2.1.0",
"@angular/http": "~2.1.0",
"@angular/platform-browser": "~2.1.0",
"@angular/platform-browser-dynamic": "~2.1.0",
"@angular/router": "~3.1.0",
"bootstrap": "^3.3.7",
"core-js": "^2.4.1",
"jquery": "^3.1.1",
"rxjs": "5.0.0-beta.12",
"ts-helpers": "^1.1.1",
"zone.js": "^0.6.23"
},
Same error than @masagatech trying to fix it right now.
same error @masagatech trying to fix it right now
@iurii-kyrylenko I am transpiling my code with babel and I m using a decorator plugin. That s why I can use decorators without Typescript and I don t have a tsconfig file.
Thank you
Laurențiu