Louis
Louis

Reputation: 2023

Angular 5 load directive after an event occurs

I have my HomepageComponent that holds a custom directive MapDirective, bound to the selector name myMap.

In homepage.component.html

  ...
  <div myMap position=??></div>
  ...

I would like the directive to be loaded only after I retrieved the location from my HomepageComponent, so that I can center my map on the user location when I display it.

This requires to wait a little bit so that I can retrieve the location using navigator.geolocation.getCurrentPosition async call.

Is it possible to do so ?

Upvotes: 1

Views: 278

Answers (1)

Pterrat
Pterrat

Reputation: 1710

If you want to display a div or other tag with condition, you can use *ngIf

<div *ngIf="position" myMap position=??></div>

So you will only display position div when you resolve the promise of getposition call

Upvotes: 1

Related Questions