Access to alpine component in custom directive #2034
-
Is there a way to access the component scope inside a custom directive? I am trying to add a method to component when a directive is present. When I try to access "this" inside the directive, or inside an evaluate function like this: I get a message like this: "_this is undefined" This is basically want I want to achieve: is that possible? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Not in that way, you can hack it without evaluate if you use Alpine.closestRoot(el), getting the data from there and injecting the method but... I'm curious about the use case. If you don't want to redefine the same function in multiple components, you can use a global function or an alpine store. |
Beta Was this translation helpful? Give feedback.
Not in that way, you can hack it without evaluate if you use Alpine.closestRoot(el), getting the data from there and injecting the method but... I'm curious about the use case. If you don't want to redefine the same function in multiple components, you can use a global function or an alpine store.