Question

Before using iron-router I attached events using:

Template.templatename.events = {};

With iron-router, you pass data through the data attribute in the route, and generally don't touch the global Template object... so where should I put events? Should I continue to use Template.tempaltename.events?

Are you supposed to use the global Template object in conjunction with iron-router?

Was it helpful?

Solution

You confuse two things: template "class" and template "instance". With Template.name.events you create global behavior of the application: how given templates is rendered, how it reacts to data, to user events.

The data you send with router is attached to a given template instance, that is the single DOM node related object that is displayed on the web page.

So yes, you should still use Template.name.events, as well as you can use Template.name.rendered, .created, .deleted, .customDataHelper and so on.

 


 

By the way, it's better to use the full version of the events:

Template.name.events({
   ...
});

It saves you from a few problems in the long run.

OTHER TIPS

Yeah, I'd continue to attach events like that. Iron router doesn't really change the way the UI works. However, I'd keep an eye for updates, because the new Meteor UI the dev team is working on will be ready probably within the next month or two, at which point this will all change anyway.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top