2016-12-29 72 views
3

我是新來的這個框架,我想知道是否有一個組件綁定,允許您指定要在常規HTML元素上使用的組件,而不是定製的組件。我們假設有一個Message組件。是否可以使用它作爲:中Aurelia組件綁定

<div component="message"></div> 

代替

<message></message> 

Knockout.js支持此它們的成分:The "component" binding.

回答

6

沒錯!您可以使用as-element自定義屬性來執行此操作。

下面是一個例子:https://gist.run?id=5fc98df81dff7eec2868ea918f6342fb

app.html

<template> 
    <require from="./message"></require> 

    <message say="Say"></message> 

    <div as-element="message" say.bind="what"></div> 
</template> 

app.js

export class App { 
    what = 'What!' 
} 

message.html

<template> 
    <h1>${say}</h1> 
</template> 

message.js

import {bindable} from 'aurelia-framework'; 

export class MessageCustomElement { 
    @bindable say = ''; 
} 

呈現

enter image description here