How to initialize the alpine component AFTER an event. #517
Replies: 5 comments 4 replies
-
@JuanDeLeon There's no native way to defer the registration of an Alpine component at the moment, but similar discussions have been had before. You could work around it by including the You could also set a timeout for a second (hopefully gmaps has loaded by then) and run your code then. |
Beta Was this translation helpful? Give feedback.
-
Other 2 options:
|
Beta Was this translation helpful? Give feedback.
-
Awesome, thanks a lot guys.
|
Beta Was this translation helpful? Give feedback.
-
Thanks to the suggestion from @SimoTod, we could solve a small challenge. Just published a blog post for future reference. |
Beta Was this translation helpful? Give feedback.
-
Hi Guys, I am having some issues when using alpine data inside the table column where jQuery datatable plugin has been used. I am not able to take advantage of x-data if I initialize datatable for the table. Sorry I have not created fiddle yet but here is some code. So basically here
|
Beta Was this translation helpful? Give feedback.
-
I'm trying to use the google maps API, and setting some initial Markers on page load.
I have my component defined like this.
<div x-data="getData()" x-init="initMarkers">...</div>
On x-init, I call my initMarkers method to create some markers:
user.marker = new google.maps.Marker({...})
However, at this point the google api script may not be loaded yet. And I get a "google is not defined" message.
<script async defer src="https://maps.googleapis.com/maps/api/js?key=mykey&callback=initMap"> </script>
So, my thought was to initialize the Alpine component inside the initMap() function, which is called after google is done. I'm not sure if this is even possible though. Any input appreciated.
Beta Was this translation helpful? Give feedback.
All reactions