将自定义属性传递到Aurelia组件

时间:2016-02-18 19:27:55

标签: aurelia

我在将属性传递到自定义组件时遇到了一些麻烦。我尝试通过以下方式声明我的组件:

<require from="../components/project-documents"></require>

<project-documents projectId="testing123"></project-documents>
<project-documents projectId.bind="project.Name"></project-documents>
import {customElement, bindable} from "aurelia-framework";
import {autoinject} from "aurelia-dependency-injection";

@customElement("project-documents")
export class ProjectDocuments {

    @bindable projectId:string;

    attached() {
        alert(this.projectId);
    }
}

调用警报时,undefined是我从中获取的值。另外,是否需要customElement装饰器?

1 个答案:

答案 0 :(得分:7)

不要使用camelCase作为属性,请尝试使用破折号。

试试这个:

<project-documents project-id="testing123"></project-documents>
<project-documents project-id.bind="project.Name"></project-documents>

根据aurelia惯例,dash-case&lt; d属性将在ViewModel中转换为camelCase变量,因此您的VM已经很好了。

相关问题