Is it possible to load an ng2 + app manually from javascript?
The situation is approaching from the wrong end.
To do this, platformBrowserDynamic
and AppModule
should be open to the global scope, but it is not. While it is possible to load Angular as UMD modules and have it as ng
global, this will result in 2 copies of Angular and AppModule
not available.
This is possible by exposing the function to the global scope:
window.bootstrapApp = () => platformBrowserDynamic().bootstrapModule(AppModule);
But given that the goal is to quickly validate users' rights with Angular code, the right place to do this is still main.ts
. And the preferred way to defer application initialization is to check the checks on the download with the APP_INITIALIZER
provider .
source to share