Does Aurelia
support optional binding? I can't find this information anywhere. The issue that I'm having is that I have a title
attribute that might or might not be populated in an array of objects. I use a repeat.for
and title.bind
but I don't want the attribute to exist at all if this property is not part of the array of objects. Is that possible in Aurelia
?
When using Bootstrap-Select
with an empty title
it throws an error. Having Aurelia
to create attribute on the fly would resolve my issue.
The code that I have so far, looks like this
<select class="selectpicker" value.bind="value" options.bind="options" disabled.bind="disabled">
<option repeat.for="option of options" model.bind="option"
data-subtext.bind="option.subtext"
title.bind="option.title">
${option.name}
</option>
In this example, I would like to make data-subtext
and title
as optional attributes. Is that doable?
Since this is a Custom Element, I tried deleting the title
property of my object delete this.element.title
but that doesn't seem to work. I also tried with jquery but again no luck.
I did not test this in many cases, but I think you could also create a custom binding behavior, like this:
And then use it like:
You could use a custom-attribute that generates a
title
attribute only if the property exists. For example:Running example: https://gist.run/?id=f7f89f35b62acb5b4f05ffe59be1880e