I created a custom element as follows
import { autoinject, bindable, bindingMode } from "aurelia-framework";
@autoinject
export class SearchBox {
@bindable public collection;
@bindable({ defaultBindingMode: bindingMode.twoWay }) public value;
@bindable public optionLabel = "";
constructor(private readonly el: Element) { }
public valueChanged(newValue, oldValue) {
if (newValue === this.optionLabel) {
return;
}
if (newValue !== oldValue) {
this.notify();
}
}
private notify() {
this.el.dispatchEvent(new CustomEvent("change", {
bubbles: true,
detail: {
value: this.value
}
}));
}
}
<template>
<div class="input-group">
<div class="input-group-append">
<i class="input-group-text fas fa-search"></i>
</div>
<select class="custom-select" value.bind="value">
<option if.bind="optionLabel !='">${optionLabel}</option>
<option repeat.for="item of collection" model.bind="item">${item.name}</option>
</select>
</div>
</template>
The bug is in the line
if.bind="optionLabel != '"
- i.e. it is missing the closing quote - it should be
if.bind="optionLabel != ''"
Obviously it should have been written simply as if.bind="optionLabel"
So the problem is that using webpack and the new aurelia-cli bundler the code compiles fine. However, at run-time, the application hangs, and gives no warning messages at all.
It was only after installing Firefox that I could see that I could see in the console that it wasn’t loading search-box
[HMR] connected client.js:92
DEBUG [aurelia] Configured plugin aurelia-dialog. aurelia-logging-console:20:6
DEBUG [aurelia] Loading plugin aurelia-validation. aurelia-logging-console:20:6
DEBUG [aurelia] Configured plugin aurelia-validation. aurelia-logging-console:20:6
DEBUG [aurelia] Loading plugin bcx-aurelia-reorderable-repeat. aurelia-logging-console:20:6
DEBUG [aurelia] Configured plugin bcx-aurelia-reorderable-repeat. aurelia-logging-console:20:6
DEBUG [aurelia] Loading plugin aurelia-animator-css. aurelia-logging-console:20:6
DEBUG [aurelia] Configured plugin aurelia-animator-css. aurelia-logging-console:20:6
DEBUG [aurelia] Loading plugin resources/index. aurelia-logging-console:20:6
DEBUG [aurelia] Configured plugin resources/index. aurelia-logging-console:20:6
DEBUG [aurelia] Loading plugin aurelia-testing. aurelia-logging-console:20:6
DEBUG [aurelia] Configured plugin aurelia-testing. aurelia-logging-console:20:6
DEBUG [templating] importing resources for resources/elements/loading-indicator
Array []
aurelia-logging-console:20:6
DEBUG [templating] importing resources for resources/elements/status-bar.html
Array []
aurelia-logging-console:20:6
DEBUG [templating] importing resources for resources/elements/search-box.html
Array []
aurelia-logging-console:20:6
DEBUG [templating] importing resources for resources/elements/nav-menu.html
Array []
aurelia-logging-console:20:6
I don’t make this kind of mistake very often - but it would oh so great if some kind of warning could be given!