K
K
Konstantin2021-02-08 23:36:10
Angular
Konstantin, 2021-02-08 23:36:10

How to pass ViewChild to APP_INITIALIZER?

I have some third-party library that is asynchronously initialized and returns a promise after initialization.

The input receives a container in the HTML element in which to render.

export class MapApi {
  constructor(container: HTMLElement, props: MapProps = {}) {}
}


In an angular application, I wait for the map to be fully initialized via `APP_INITIALIZER`. But how to transfer the container there - after all, at this stage there is no tempate yet

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Kayun, 2021-02-10
@Junart1

At the initialization stage, there are no ViewChilds yet, since the template has not yet been initialized. As you yourself wrote. Therefore, you cannot pass an HTMLElement to an initializer.
The disadvantage of your solution is that the whole application waits for the map to be initialized and does not render anything at all. The best solution would be to create a separate component for the map and inside this component already asynchronously load and initialize the map. And at the time of loading / initializing, show some kind of loader or stub. In this case, you will show the user at least the skeleton of the application, and when ready, the map.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question