Ember components in subdirectory

隐身守侯 提交于 2019-12-08 15:50:15

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/29038704/ember-components-in-subdirectory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!