Reputation: 138
I am creating an Ember application as an add-on to some HTML returned from the server. I need this HTML so that the site can be indexed by search engines, and also to speed up the initial page rendering for the users.
So my application consists of several Ember Views, appended to different DOM elements of the HTML generated by the server. I don't use master templates for routes, so I set renderTemplate function of each route to do nothing.
My Ember App is bound to body element and I can successfully append a custom view to an element down the tree. It works:
In this JSFiddle three last elements of the list are appended by Ember
But when I try to use linkTo helper in my template, I hit an error:
Uncaught TypeError: Cannot read property 'container' of null ember-latest.js:32224
which is in this function:
router: Ember.computed(function() {
return get(this, 'controller').container.lookup('router:main');
}),
In this JS fiddle I just add linkTo to the template, and it breaks everything
Upvotes: 1
Views: 2062
Reputation: 138
I found that I need to additionally bind the view and the container together to make this fiddle work
App.itemsView.set("controller", App.itemsController);
App.itemsController.set("container", this.container);
So the resulting working code snippet is here: http://jsfiddle.net/ddegtyarev/6cBRx/6/
Again, let me reiterate that I'm building an hybrid Ember application - i.e. I have some HTML returned right from the server, and some appended by multiple Ember views in multiple places. This is why I have to manually create the views and bind them with controllers etc.
Upvotes: 0
Reputation: 1463
I've fixed your fiddle here, Check it out.
Seems like you are starter to Ember,
So here are some tips for you,
application
template, which will be the root template and on which all the templates will be rendered. views
using this.container.lookup
, that is for debugging only.views
to the DOM, it's the job of the framework to do. rootElement
property when creating the application
. Refer here for configuring your application
.The rootElement can be either a DOM element or a jQuery-compatible selector string. Note that views appended to the DOM outside the root element will not receive events. If you specify a custom root element, make sure you only append views inside it!
App.itemsController.set("content", model)
, if you want to access another controller
inside a route, use this.controllerFor
, and to access inside another controller
, use needs
. App.itemsController=Ember.ArrayController.extend({}).create();
Upvotes: 2