Skip to content

Conversation

@arturovt
Copy link
Contributor

@arturovt arturovt commented Jul 6, 2022

The injector getter is annotated with @internal and is removed from declarations.
This commit removes the annotation thus it's possible to access the injector on the
ApplicationRef, e.g., after calling bootstrapApplication.

Currently, it requires casting ApplicationRef to { injector: Injector } after calling the bootstrapApplication, e.g.:

bootstrapApplication(...).then((appRef) => {
  const injector = (appRef as unknown as { injector: Injector }).injector;
  const router = injector.get(Router);
  ...
});

NgModuleRef prior to ApplicationRef has a public injector property which allows the above behavior:

platformBrowserDynamic()
  .bootstrapModule(...)
  .then((ngModuleRef) => {
    const router = ngModuleRef.injector.get(Router);
    ...
  });

This change also allows a more straightforward setup for micro-frontend adapters (e.g., single-spa-angular). The micro-frontend bootstrap function can resolve to ApplicationRef | NgModuleRef<T>; they both have the destroy method now, and having injector on both types doesn't require type cast for ApplicationRef.

The `injector` getter is annotated with `@internal` and is removed from declarations.
This commit removes the annotation thus it's possible to access the `injector` on the
`ApplicationRef`, e.g., after calling `bootstrapApplication`.
@pkozlowski-opensource
Copy link
Member

Thnx, but we are going to go with #46665 instead

@arturovt arturovt deleted the fix/core-injector-internal branch July 6, 2022 17:17
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Aug 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants