Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Could APP_INITIALIZER depend on ApplicationRef ? #9101

Closed
vicb opened this issue Jun 8, 2016 · 8 comments
Closed

[Core] Could APP_INITIALIZER depend on ApplicationRef ? #9101

vicb opened this issue Jun 8, 2016 · 8 comments
Assignees
Labels
feature Issue that requests a new feature state: Needs Design

Comments

@vicb
Copy link
Contributor

vicb commented Jun 8, 2016

Right now APP_INITIALIZERs can not have a dependency on ApplicationRef because the initializers are executed in ApplicationRef_ ctor.

Would there be a way to allow such a dep ? (ie execute the initializers after the ApplicationRef_ is constructed ?)

/cc @tbosch @vsavkin

(the use case is APP_INITIALIZER -> Router -> AppRef)

@PatrickJS
Copy link
Member

@vicb can you take a look at #9110 that allows for this

@tbosch
Copy link
Contributor

tbosch commented Jun 23, 2016

We could change this.
However, there is a more general problem to solve: If the router should be provided at a component (and not to the bootstrap call), app initializers won't run any more. A possible solution would be to support Provider.eager...

@tbosch
Copy link
Contributor

tbosch commented Jun 23, 2016

Reviewed #9110 and added some comments. But it is the right change for now, as adding eager providers would be a bigger change...

@PatrickJS
Copy link
Member

it seems like we just need more lifecycle hooks for platform/application (sometime like: beforebootstrap, afterbootstrap, beforetick, aftertick)

@simperreault
Copy link

Just to point out an issue created by this one. When we try to navigate in the OnInit function of the RootComponent, the navigate event is cancelled. This happen because the method initialNavigation() on Router is called after the initialization of the RootComponent and cancelling the current ongoing navigation event. This is caused by the setTimeout() here https://github.com/angular/angular/blob/master/modules/@angular/router/src/common_router_providers.ts#L54-L61.

It should be fix with this issue with the increase of lifecycle hooks (or whatever strategy you guys intent to do)

@lacolaco
Copy link
Contributor

lacolaco commented Jul 6, 2016

After introducing AppModule, we maybe want something lifecycle method like ngModuleLoaded in a module class.

@tbosch
Copy link
Contributor

tbosch commented Jul 7, 2016

Modules are eager, i.e. their constructor can be used as an app initializer
as well.
On Wed, Jul 6, 2016 at 4:58 PM Suguru Inatomi notifications@github.com
wrote:

After introducing AppModule, we maybe want something lifecycle method
like ngModuleLoaded in a module class.


You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
#9101 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AAqKf4AcDRCp9JIz-JQWiJialblYyJFiks5qTEE-gaJpZM4IxfHU
.

tbosch added a commit to tbosch/angular that referenced this issue Jul 29, 2016
This makes `bootstrapModuleFactory` wait for promises
returned by `APP_INITIALIZER`s, also making `bootstrapModuleFactory` async.
I.e. now `bootstrapModule` and `bootstrapModuleFactory` behave in the
same way.

This ensures that all code form module instantiation, to creating
`ApplicationRef`s as well as calling `APP_INITIALIZERS` is run
in the Angular zone.

This also moves the invocation of the initializers form the `ApplicationRef`
constructor into the `bootstrapModuleFactory` call, allowing initializers
to get a hold of `ApplicationRef` (see angular#9101).

Closes angular#9101
Closes angular#10363

BREAKING CHANGE:
- Deprecates:
  * `ApplicationRef.waitForAsyncInitializers`: No more needed as
    `bootstrapModule` and `bootstrapModuleFactory` automatically wait for
    promises returned by initializers.
tbosch added a commit to tbosch/angular that referenced this issue Jul 29, 2016
This makes `bootstrapModuleFactory` wait for promises
returned by `APP_INITIALIZER`s, also making `bootstrapModuleFactory` async.
I.e. now `bootstrapModule` and `bootstrapModuleFactory` behave in the
same way.

This ensures that all code form module instantiation, to creating
`ApplicationRef`s as well as calling `APP_INITIALIZERS` is run
in the Angular zone.

This also moves the invocation of the initializers form the `ApplicationRef`
constructor into the `bootstrapModuleFactory` call, allowing initializers
to get a hold of `ApplicationRef` (see angular#9101).

Closes angular#9101
Closes angular#10363

BREAKING CHANGE:
- Deprecates:
  * `ApplicationRef.waitForAsyncInitializers`: No more needed as
    `bootstrapModule` and `bootstrapModuleFactory` automatically wait for
    promises returned by initializers.
tbosch added a commit to tbosch/angular that referenced this issue Aug 1, 2016
This makes `bootstrapModuleFactory` wait for promises
returned by `APP_INITIALIZER`s, also making `bootstrapModuleFactory` async.
I.e. now `bootstrapModule` and `bootstrapModuleFactory` behave in the
same way.

This ensures that all code form module instantiation, to creating
`ApplicationRef`s as well as calling `APP_INITIALIZERS` is run
in the Angular zone.

This also moves the invocation of the initializers form the `ApplicationRef`
constructor into the `bootstrapModuleFactory` call, allowing initializers
to get a hold of `ApplicationRef` (see angular#9101).

Closes angular#9101
Closes angular#10363
tbosch added a commit to tbosch/angular that referenced this issue Aug 1, 2016
This makes `bootstrapModuleFactory` wait for promises
returned by `APP_INITIALIZER`s, also making `bootstrapModuleFactory` async.
I.e. now `bootstrapModule` and `bootstrapModuleFactory` behave in the
same way.

This ensures that all code form module instantiation, to creating
`ApplicationRef`s as well as calling `APP_INITIALIZERS` is run
in the Angular zone.

This also moves the invocation of the initializers form the `ApplicationRef`
constructor into the `bootstrapModuleFactory` call, allowing initializers
to get a hold of `ApplicationRef` (see angular#9101).

Closes angular#9101
Closes angular#10363
@tbosch tbosch closed this as completed in a46437c Aug 1, 2016
@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 Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature Issue that requests a new feature state: Needs Design
Projects
None yet
5 participants