【问题标题】:Replace Custom Element with template itself (rather than including it inside the custom element) in Aurelia?在 Aurelia 中用模板本身(而不是将其包含在自定义元素中)替换自定义元素?
【发布时间】:2015-12-19 04:33:22
【问题描述】:

假设我有一个自定义元素 <foo-bar></foo-bar> 我不想将标记呈现到标签中,而是想替换它们,以便“foo-bar”元素不再是 DOM 的一部分。我相信 Angular 是通过 transclude 属性做到这一点的。

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

【问题讨论】:

    标签: javascript aurelia


    【解决方案1】:

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

    来自文档的Custom Elements Section:

    @containerless() - 使元素的视图在没有自定义元素容器包装的情况下呈现。这不能与@sync 或@useShadowDOM 一起使用。它也不能与代理行为一起使用。

    所以你的组件应该是这样的:

    import {customElement, bindable, containerless} from 'aurelia-framework';
    
    @customElement('say-hello')
    @containerless()
    export class SayHello {
      @bindable to;
    
      speak(){
        alert(`Hello ${this.to}!`);
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-06
      • 1970-01-01
      • 1970-01-01
      • 2018-03-27
      相关资源
      最近更新 更多