3

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

I need something like we do in TypeScript:

platformBrowserDynamic().bootstrapModule(AppModule);
9
  • 1
    this line will work in JavaScript as well, also read How to manually bootstrap an Angular application Commented Jul 24, 2017 at 9:09
  • Is there a way to bootstrap module from jQuery code on my page? I'm trying to use the code I've provided above, but have errors.. Commented Jul 24, 2017 at 9:51
  • I believe this will be a pretty big answer with lots of nuances... As I said, the line you referenced will work in a browser regardless from it's executed Commented Jul 24, 2017 at 9:52
  • can you help me? Commented Jul 24, 2017 at 9:53
  • sorry, your question is too broad, try to make it specific Commented Jul 24, 2017 at 9:56

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.