user2135804
user2135804

Reputation: 21

Can't call "on" to bind methods

I cant register any events with the "on" Mehotd.

Uncaught TypeError: Cannot call method 'on' of undefined

Ext.define('faragoo.view.Main', {

extend: 'Ext.Container',
alias: 'widget.stream',
xtype: 'stream',
id : 'stream',   
requires: [
    'Ext.TitleBar',
    'Ext.form.Panel'
],

initialize: function () {

   this.on('afterrender', function() { alert('rendered'); } );

}

}

And this simple example doesnt work also :

Ext.Viewport.on('orientationchange', function() { console.log("orientationchange"); }, this, {buffer: 50 });

Same Error :-(

Upvotes: 2

Views: 80

Answers (1)

A1rPun
A1rPun

Reputation: 16847

This guide explains how to properly add events to a component.

Bind the event after the component is created:

var myButton = Ext.Viewport.add({
    xtype: 'button',
    text: 'Click me'
});

myButton.on('tap', function() {
    alert("Event listener attached by .on");
});

Or bind an event with using a listener config:

Ext.Viewport.add({
    xtype: 'button',
    text: 'My Button',
    listeners: {
        tap: function() {
            alert("You tapped me");
        }
    }
});

Upvotes: 1

Related Questions