I want to set the binding context for my custom element. something like
<my-custom-element context.bind="someproperty"></my-custom-element>
How can this be achieved? Thanks.
I want to set the binding context for my custom element. something like
<my-custom-element context.bind="someproperty"></my-custom-element>
How can this be achieved? Thanks.
If you're trying to access the parent binding context from within a custom element, you can simply use $parent.someproperty
in the view to go up a level. If all you need to do is access the parent you can combine this with with.bind="$parent"
It's the other way around but it accomplishes the same thing.
Setting the binding context of a custom element in itself doesn't really make sense because that would mean you're changing the ViewModel
if you want to know the binding context within the component/custom element you can access it from the bind
component lifecycle method, i.e.:
class MyCustomElement {
context;
bind(context, overrideContext) {
this.context = context;
}
}
https://aurelia.io/docs/fundamentals/components#the-component-lifecycle for my details