在 Aurelia 中用模板本身替换自定义元素(而不是将其包含在自定义元素中)?

Replace Custom Element with template itself (rather than including it inside the custom element) in Aurelia?

假设我有一个自定义元素 <foo-bar></foo-bar> 我不想将标记渲染到标签中,而是想替换它们,以便 "foo-bar" 元素不再是 DOM 的一部分。我相信 Angular 通过嵌入 属性.

来做到这一点

有没有办法在 Aurelia 中做到这一点?

您需要在您的组件上使用 containerless 装饰器。

来自文档的 Custom Elements Section:

@containerless() - Causes the element's view to be rendered without the custom element container wrapping it. This cannot be used in conjunction with @sync or @useShadowDOM. It also cannot be uses with surrogate behaviors.

因此您的组件应如下所示:

import {customElement, bindable, containerless} from 'aurelia-framework';

@customElement('say-hello')
@containerless()
export class SayHello {
  @bindable to;

  speak(){
    alert(`Hello ${this.to}!`);
  }
}