Skip to content

Instantly share code, notes, and snippets.

@jack4it
Created December 30, 2015 01:55
Show Gist options
  • Save jack4it/da9e699d7e6968b210be to your computer and use it in GitHub Desktop.
Save jack4it/da9e699d7e6968b210be to your computer and use it in GitHub Desktop.
export class SystemLazyLoadService {
static $inject = ["$ocLazyLoad"];
constructor($ocLazyLoad) {
this.$ocLazyLoad = $ocLazyLoad;
}
load(src, moduleExportKey) {
let loader = this.$ocLazyLoad;
return System.import(src)
.then(module => {
var angularModule = module[moduleExportKey || 'default'];
if (!angularModule) {
console.info(module);
throw new Error("Unexpected angular module");
}
return loader.load(angularModule);
})
.then(() => {
return null; // !!! critical here; this is needed to trick future state infra
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment