How to add a binding behavior from view model?

I’m making a plugin, and I want to add a binding behavior to a bindable property on my custom element instead of requiring others to use the behavior in their templates, is this possible? maybe with @processContent?

1 Like

Yes - the property on your view model can be decorated like below:

import { bindable, bindingMode } from 'aurelia-binding';
...
@bindable({defaultBindingMode: bindingMode.oneTime}) setOnce;

I believe the caller can still override this, but if they use the generic bind then they’ll get your default configured binding behaviour.
<myelement set-once.bind="'test'"></myelement >

1 Like

Very close to what you need.

1 Like

I found a good example of how I can achieve this here: https://github.com/Foursails/aurelia-plus/blob/master/src/type-custom-attribute.js

1 Like