使用撰写

时间:2016-07-25 10:14:00

标签: aurelia aurelia-templating

可以使用@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>与否。{1}}。我认为自定义元素应该与此外部决策隔离开来。在这两种情况下我们都可以@bindable工作吗?

1 个答案:

答案 0 :(得分:0)

<compose>呈现的自定义元素可以访问其外部作用域。因此,无需使用@bindable。请参阅此示例https://gist.run/?id=fae6b9c9c2e3a608a60522392329bae1