Adam
Adam

Reputation: 57

Ember.JS and ember-data throwing cryptic error messages when using Router

I'm working on a saved search feature for an Ember application, with the general idea being that after conducting a search you have the option to enter a shortname for the search and save it to localStorage and retrieve it later from a dropdown list, while also being able to share the current URL with other users and have them see the same search.

This works through a combination of the Ember Router handling search params in the URL and a view that handles the user clicking 'save' (the view is included in a fiddle, but is not able to be run as no templates are included -- see below).

Whenever I run the application, I get the following error:

Uncaught TypeError: Cannot call method 'set' of undefined 

You can see the trace in the fiddle listed below, however it appears to stem from the controller store injection in ember-data. Unfortunately my knowledge of Ember[-data] doesn't extend far enough to know how this relates to the rest of the application.

I've taken the relevant parts of the application that should work independently and run them in a JSFiddle, but that still results in the same error. The fiddle is located at http://jsfiddle.net/fetcU/. Currently there are no handlebars templates or anything in that fiddle as they don't contribute to the problem.

The localStorage adapter and other parts worked fine independently until the Router was introduced, and so it may be related to the code now being run by Checklist.initialize() (which wasn't necessary until the Router was added).

I've compared this to other similar projects and examples, particularly those given for ember-data, and it's not entirely clear what I'm doing wrong here. I'd appreciate any insight!

Upvotes: 1

Views: 519

Answers (2)

tygirl76
tygirl76

Reputation: 86

Did you try making your controller a class? So, instead of Checklist.savedSearchController, try Checklist.SavedSearchController.

Upvotes: 0

sly7_7
sly7_7

Reputation: 12011

First thing: When you create an app with a router, you don't have to create instances of Store, Controllers, Views. When calling App.initialize(), ember will do the instantiation and injection for you.

Then, you will have access:

  • controllers, via the router (in the connectOutlets()), by router.get(xxxController), where xxx is for example application (to access the base controller), or savedSearch to access your savedSearchController.
  • the store, from the router by invoking router.get('store')
  • a xxxController from a xxxView by invoking this.get('controller'), or from the templates with view.controller
  • the router from the controllers, by invoking this.get('target')

Well, I let you try modifying the code. Let me now when you are stuck again :)

Upvotes: 3

Related Questions