2016-12-02 26 views
0

我在奥里利亚使用打字稿(2.0)的自定义元素,并希望结合一些值,但它只是不工作。这是我的例子:Aurelia大街与打字稿:结合使用性能不工作

myelement.html:

<template> 
    <div>${caption}</div> 
    <div>${unit}</div> 
</template> 

myelement.ts:

import { bindable } from "aurelia-framework"; 

export class MyElement { 
    // removing the @bindable doesn't change anything 
    @bindable public caption: string; 
    @bindable public unit: string; 
} 

用法:

<require from="./myelement"></require> 
... 
<myelement caption.bind="currentvalue" unit=" km"></myelement> 

的CurrentValue的属性是使用定义的(在类定制元素)为

public currentvalue: number = 11; 

的myelement正确插入,但占位符与空文本替换(即删除),甚至是“单位”,这只是一个文本。

什么有趣的是它的 “单位” 工作的占位符是:

myelement.html:

<template bindable="unit"> 
    <div>${caption}</div> 
    <div>${unit}</div> 
</template> 

在这种情况下,${unit}由 “公里” 所取代。

不知怎的Aurelia路上没有得到自定义元素的HTML和视图模型之间的连接。使用可绑定属性的绑定工作,但仅限于未绑定到属性。 myelement.js文件被正确加载(我使用SystemJS和AMD模块)。 我错过了什么?

更新: - 在模板中的占位符正确地“公里”取代

我myelement.ts @bindable@bindable()现在的“单位”正确绑定改变。但是使用属性的绑定(我的例子中的标题)仍然不起作用。

更新2: 最后,我得到它的工作。父自定义元素(使用myelement)使用<require from="./myparentelement.html">所以它的视图模型不连接被列入...

+1

我认为你的元素名称应该是''而不是'',因为Aurelia默认使用连字符为每个新的大写单词分隔类名。尝试更改使用中的元素,看看它是否有所作为。或者将您的课程名称从“MyElement”更改为“Myelement”。 – LStarky

+0

尝试用括号编写@bindable()。我前段时间阅读了一些关于TypeScript中的错误,当缺少()时导致奇怪的行为。另外,您将单位约束为“km”,并且似乎期望字符串可以传递到UI,但在这种情况下km会被解释为属性。创建一个单位属性,并将其值设置为'km',然后绑定到该 – mgiesa

+0

@Larkark这有助于加载正确的文件,但没有绑定。 –

回答

0

没有正确所需的父自定义元素: <require from="./myparentelement.html">代替<require from="./myparentelement">,我不得不使用@bindable()代替@bindable