Vnuuk
Vnuuk

Reputation: 6527

Is it possible to bootstrap ng2+ app manually from javascript?

Is it possible to bootstrap NG2+ app manually from jquery / javascript code?

I need something like we do in TypeScript:

platformBrowserDynamic().bootstrapModule(AppModule);

Upvotes: 3

Views: 37

Answers (1)

Estus Flask
Estus Flask

Reputation: 222493

The situation is being approached from wrong end.

In order to do that, platformBrowserDynamic and AppModule should be exposed to global scope, and they aren't. While it is possible to load Angular as UMD modules and have it as ng global, this would result in 2 copies of Angular, and AppModule would still be unreachable.

It's possible by exposing a function to global scope:

window.bootstrapApp = () => platformBrowserDynamic().bootstrapModule(AppModule);

But considering that the objective is to quickly check user permissions with non-Angular code, the right place to do this is still main.ts. And the preferable way to postpone application initialization is to do checks on bootstrap with APP_INITIALIZER provider.

Upvotes: 3

Related Questions