I am creating an Aurelia custom element and I want to use the special Binding behavior, but I cannot use it (declare) outside the Custom Element class. Also, I was wondering if there is a namespace in Aurelia for Binding Behaviors and other custom materials?
Here's the binding behavior I want to use
optional-binding.js - code provided by another stack question
export class OptionalBindingBehavior {
bind(binding, scope, interceptor) {
binding.originalupdateTarget = binding.updateTarget;
binding.originalTargetProperty = binding.targetProperty;
binding.updateTarget = val => {
if (val === undefined || val === null || val === '') {
binding.targetProperty = null;
} else {
binding.targetProperty = binding.originalTargetProperty;
}
binding.originalupdateTarget(val);
};
}
unbind(binding, scope) {
binding.updateTarget = binding.originalupdateTarget;
binding.originalupdateTarget = null;
binding.targetProperty = binding.originalTargetProperty;
binding.originalTargetProperty = null;
}
}
I tried to import this path
index.js
import {MyCustomElement} from './my-element';
import './optional-binding.js';
export function configure(aurelia) {
aurelia.globalResources('./my-element');
}
export {
MyCustomElement
};
and also tried import './optional-binding.js';
directly in the user element, but in all cases he says that he cannot find this binding.
, ( ), , /.
@janmvtrinidad require
, , , ViewModel. , , ./
. , , , .
()
<template>
<require from="./optional-binding"></require>
...
,
Cannot find module './aurelia-bootstrap-select/optional-binding'
/
, , Aurelia-Bootstrap-Select. , - , OptionalBindingBehavior
, , .
, , , , Aurelia.