1

The CanJS documentation has an example like this:

var Todos = can.Control.extend({
    init: function( element , options ) { ... },

    'li click': function( li ) { ... },
    'li .destroy {destroyEvent}': function( el, ev ) { 
        // previous destroy code here
    }
});
// create Todos with this.options.destroyEvent
new Todos( '#todos', { destroyEvent: 'mouseenter' } );

However, if #todos is created after new Todos is called, no event is bound the future element, or if a method within Todos removes a pre-created #todos dummy as deemed necessary. How can I rebind custom events within a Control? After a Control instantiation call?

ramblinjan
  • 6,578
  • 3
  • 30
  • 38
Brian
  • 7,394
  • 3
  • 25
  • 46

1 Answers1

1

Just use Control.on(); http://canjs.com/docs/can.Control.prototype.on.html

You can specifiy which event to be listen to or just call the function without parameters like this the control listen to all events.

Cherif BOUCHELAGHEM
  • 1,126
  • 2
  • 14
  • 21
  • The controller is binded to the element you send as a parameter, why would you instantiate a controller if the element you are going to bind it doesn't exist yet? – rdk1992 Dec 11 '14 at 14:17