I have a custom element hierarchy that looks like select-single <- dropdown <- dropdown-wrapper
where each name is a custom element and each arrow represent a template that uses that custom element.
When I use select-single
, the attached
handler calls selectedChanged()
with options
set to the bound value, but doSelect
is undefined. After the page is displayed, clicking an element in the select-single
control fires the click.trigger
and both bound properties are valid values.
Is there a rule about Aurelia lifecycles that prevents the doSelect
function from being bound, even though options
is bound at the same lifecycle step?
select-single.html
<template>
<div class="select-single"
if.bind="options.length">
<label
class="select-single-option"
repeat.for="option of options"
click.trigger="selectedChanged(option)">
${option.name}
</label>
</div>
</template>
select-single.js
import {
bindable
} from 'aurelia-framework';
@bindable({
name: 'options',
defaultValue: []
})
@bindable({
name: 'doSelect',
defaultValue: null
})
export class SelectSingle {
constructor() {
let self = this;
this.selectedChanged = function(option) {
self.doSelect(option);
}
}
attached() {
for(let ii = 0; ii < this.options.length; ii++){
if(!!this.options[ii].defaultSelection){
this.selectedChanged(this.options[ii]);
}
}
}
}
index.html
<select-single options.bind="options" do-select.bind="doSelect"></select-single>