Use Alpine.data
directly on an element.
#3411
zraly
started this conversation in
3. Feature Ideas
Replies: 1 comment 1 reply
-
There is already technically an API to do this exposed on the Alpine global Or you can inline the object into the I'm not sure why you think you'd need to generate more names if it's all the same data anyway? you can just put the same data expression on multiple components. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I needed to apply
Alpine.data()
to an element, but there was a problem. The element was created by javascript (const newElement = document.createElement('div')
). It still worked when I attached thex-data
parameter to this element (newElement.setAttribute('x-data','Hello')
), but the problem was with the composition of theseHello
identifiers. For example, if I wanted to create more than one such element, I would need to have some sort of generator of their names.Wouldn't it be much better to use the
Alpine.data()
directly on the element like this?:Beta Was this translation helpful? Give feedback.
All reactions