Lazloman
Lazloman

Reputation: 1347

Ember container.lookup fails to find component

I'm trying to dynamically load an EmberJS component, but the lookup returns undefined. I'm still rather new to Ember, so I think I'm missing some concept. Here is my code:

var component = getOwner(this).lookup('component:mycomponent', {singleton: false});

This a new component that I've just created.It has its component class (.js), template(.hbs) and route. If I replace 'mycomponent' with the name of an already existing component, say otherComponent, the lookup succeeds. The new class, template and route are in the same folders as the other files of their type. I'm at a loss as to why this fails as I've used lookup before with other components. Can someone enlighten me? Do I need to somehow register the new component so that it found via lookup?

Upvotes: 0

Views: 1374

Answers (1)

Lazloman
Lazloman

Reputation: 1347

I figured it out. I haven't created a component from scratch in about 6 months and don't remember how I created the files. I created the files for this component within Sublime. With no other ideas, I went to the command line and ran 'ember g component mycomponent'. I told it to skip overwriting the existing files and it made an integration test file and then app/data/components/mycomponent.js which contained an export of the path to the class file. Now it works. I really wish the Ember docs in general were more clear about things. All they needed to tell me was how it searched for the component and I would have figured it out from there. No, instead all I get is an overview of Ember injection, with a n example of using lookup. Its often like playing 20 questions trying to figure out the docs' and two hours of googling found nothing. An easy one line (file) fix, jeez.

Upvotes: 1

Related Questions