可以使用@bindable装饰器将属性传递给Aurelia自定义元素:
export class ItemCustomElement {
@bindable model: Item;
}
<item model.bind="model"></item>为什么由<compose>呈现的自定义元素会受到不同的处理,根据文档它们需要activate方法来传递数据?@bindable是不受尊重的。
export class ItemCustomElement {
@bindable model: Item;
activate(model: Item): void {
this.model = model;
}
}
<compose view-model="./item" model.bind="model"></compose>从自定义元素的角度来看,目前它需要知道如何使用它,无论是否使用<compose>。我认为自定义元素应该从这个外部决策中分离出来。我们能让@bindable在这两种情况下都工作吗?
发布于 2016-07-25 20:49:47
由<compose>呈现的自定义元素可以访问其外部作用域。因此,不需要使用@bindable。请参阅此示例https://gist.run/?id=fae6b9c9c2e3a608a60522392329bae1
https://stackoverflow.com/questions/38565024
复制相似问题