Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor how to create global event?

Tags:

meteor

How can I create a event which will run on any page?

When creating a helper on the main layout template it doesn't work.

Template.layout.events
  'click': ->
    console.log "you clicked on the site"
like image 433
sasdev Avatar asked Feb 26 '15 17:02

sasdev


1 Answers

you need a special package to create a global event.

install

meteor add gwendall:body-events

and you can use the events from Template.body.events in every template

example

Template.body.events({
   'click .myClass':function(){
       alert("BODY EVENT");
   }
});

or if you like the new syntax

Template.body.events({
   'click .myClass'(){
       alert("BODY EVENT");
   }
});
like image 84
Dude Avatar answered Dec 25 '22 00:12

Dude