[英]Replace Custom Element with template itself (rather than including it inside the custom element) in Aurelia?
假设我有一个自定义元素<foo-bar></foo-bar>
而不是将标记呈现到标记中,我想替换它们,以便“foo-bar”元素不再是DOM的一部分。 我相信Angular通过transclude属性来做到这一点。
在Aurelia有办法做到这一点吗?
您需要在组件上使用无containerless
装饰器。
从文档的自定义元素部分 :
@containerless()
- 使元素的视图在没有自定义元素容器包装的情况下呈现。 这不能与@sync
或@useShadowDOM
一起使用。 它也不能用于代理行为。
所以你的组件应该是这样的:
import {customElement, bindable, containerless} from 'aurelia-framework';
@customElement('say-hello')
@containerless()
export class SayHello {
@bindable to;
speak(){
alert(`Hello ${this.to}!`);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.