Ember组件在子目录中 [英] Ember components in subdirectory
问题描述
我已经看到现在支持/ components中的目录/文件夹。使用ember-cli可以生成必需的子目录/组件。但是,我似乎无法引用该组件。
例如,如果我这样的文件夹结构:
app / components / sub / test-comp.js
pre>
app / templates / components / sub / test-comp.hbs
引用:(在另一个.hbs文件)
{{test-comp model = model}}
给我以下错误:
找不到名为test-comp的帮助者
ember:1.10.0
ember-cli:0.2.0{{sub / test- comp model = model}}
编辑:参考对于狮子座的问题,事实证明它是一个生成器的问题。组件生成器创建如下:
从ember导入Ember;
从'../templates/components/sub/foo-bar'导入布局;
导出默认值Ember.Component.extend({
layout:layout
});
据我所知,没有理由导入这样的布局。除非有大的变化,否则会自动发现组件布局(如果您使用默认命名约定)。我不知道为什么会这样做(可能是一个错误),但是您可以通过删除这样的导入来修复它:
从ember导入Ember;
导出默认值Ember.Component.extend({
});
编辑2:看起来像这是一个已知问题。我仍然不知道为什么手动导入布局是必要的,因为组件应该在没有它的情况下正常工作。
I've read that having directories/folders inside of /components is now supported. Using ember-cli I can generate the necessary subdirectory/component required. However, I cannot seem to reference the component.
For example if I a folder structure like this:
app/components/sub/test-comp.js app/templates/components/sub/test-comp.hbs
referencing by: (in another .hbs file)
{{test-comp model=model}}
gives me the following error:
A helper named 'test-comp' could not be found
ember: 1.10.0
ember-cli: 0.2.0解决方案You need to use the full path to the component:
{{sub/test-comp model=model}}
EDIT: In reference to the issue Leo is having, it turns out it's a generator problem. The component generator creates something like this:
import Ember from 'ember'; import layout from '../templates/components/sub/foo-bar'; export default Ember.Component.extend({ layout: layout });
As far as I'm aware, there's no reason to import the layout like that. Unless something big has changed, component layouts are discovered automatically (if you're using the default naming conventions). I don't know why it does this (could be a bug), but you can fix it by removing the import like this:
import Ember from 'ember'; export default Ember.Component.extend({ });
EDIT 2: It looks like this is a known issue. I still don't know why importing the layout manually is necessary, as the component should work just fine without it.
这篇关于Ember组件在子目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文