10

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

leojh
  • 7,160
  • 5
  • 28
  • 31

1 Answers1

19

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.

GJK
  • 37,023
  • 8
  • 55
  • 74
  • I did try that and the error is slightly different: Could not find module `myApp/components/templates/components/sub/test-comp` – leojh Mar 13 '15 at 18:01
  • That is an odd path. Is that the exact error you get? There's no reason it should be looking for a `templates` folder inside of your `components` folder. – GJK Mar 13 '15 at 18:05
  • Also, which versions of Ember and Ember-CLI are you using? – GJK Mar 13 '15 at 18:05
  • That's the error it gives. I'm on ember-cli 0.2.0 and ember 1.10.0 – leojh Mar 13 '15 at 18:06
  • 1
    I updated my answer. Turns out that the slash is correct, you just had an incorrect component generated. – GJK Mar 13 '15 at 18:14
  • Nice. I did notice that layout was coming in with new generator, but just assumed that it was required. – leojh Mar 13 '15 at 19:12