Aurelia, how to add a Binding Behavior to a user element and within its own namespace?

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.

+6
1

, Aurelia CLI, , - .. resources. globalResources. resources/index.ts config.globalResources([...]).

export function configure(config: FrameworkConfiguration) {
    config.globalResources([
        './value-converters/json',
        './binding-behaviors/intercept-one',
        './elements/pagination'
    ]);
}

require html.

Aurelia . , .

  • @CustomElement @CustomAttribute, . , ClassName InitCaps dash-case. .
  • require html. globalResources, html, globalResource ClassName -/.

, ( ), , /.

. Aurelia viewResources . , html, require, 2- .

0

Source: https://habr.com/ru/post/1016025/


All Articles