0

我有一个基本的奥里利亚组件,它看起来像当我在它的名称中使用破折号,它不起作用。奥里利亚破折号在组件名称不起作用

它工作时,我有这样的:当是这样

import {inject, customElement, bindable} from 'aurelia-framework'; 

@customElement('helloworld') 
@inject(Element) 
export class HelloWorldCustomElement { 
    constructor(element) { 
     console.log ('here') 
    } 
} 
<helloworld></helloworld> 

但事实并非如此:

import {inject, customElement, bindable} from 'aurelia-framework'; 

@customElement('hello-world') 
@inject(Element) 
export class HelloWorldCustomElement { 
    constructor(element) { 
     console.log ('here') 
    } 
} 
<hello-world></hello-world> 

根据Aurelia文档,它应该可以同时工作:https://github.com/aurelia/templating/blob/master/doc/article/en-US/templating-custom-elements.md

+0

你确定你没有在你的一个应用另一个'HELLO-world'成分,特性? –

+0

这似乎是这种情况。我正在导入一个与导致冲突的名称相同的HTML文件:'' – st3fan

回答

1

我设法找到原因。在app.html我有以下行,似乎有一个命名冲突。删除它可以立即解决问题。

<require from="hello-world/hello-world.html"></require> 
+3

另外值得注意的是,您不需要使用'customElement '装饰者,如果你通过'MyElementCustomElement'使用默认的命名约定,反之亦然。装饰器给你更多的控制,并允许你为元素命名为不同的类。 –