Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EXTjs: Uncaught TypeError: controller.setView is not a function

I am trying to get this to work in sencha fiddle. If I run it I see this error in the console log "Uncaught TypeError: controller.setView is not a function". It works only if I remove the controller declaration from the view. What am i doing wrong?

Ext.define('MyApp.controller.Whatever', {
    extend: 'Ext.app.Controller',
    alias: 'controller.Whatever',
    init: function() {
        alert("Yes!");
    }
});

Ext.define('MyApp.view.Whatever', {
    extend: 'Ext.form.Panel',
    controller: 'Whatever',
    title: 'Hello',
    width: 200,
    html: '<p>World!</p>',
    renderTo: Ext.getBody()
});

Ext.application({
    name: 'MyApp',
    launch: function() {
        Ext.create('MyApp.view.Whatever');
    }
});

Based on the answer below this worked

Ext.define('MyApp.controller.Whatever', {
    extend: 'Ext.app.ViewController',
    alias: 'controller.Whatever',
    init: function() {
        alert("Yes!");
    }
});

Ext.define('MyApp.view.Whatever', {
    extend: 'Ext.form.Panel',
    alias:'widget.Whatever',
    controller: 'Whatever',
    title: 'Hello',
    width: 200,
    html: '<p>World!</p>',
    renderTo: Ext.getBody()
});

Ext.application({
    name: 'MyApp',
    launch: function() {
        Ext.create('MyApp.view.Whatever');
    }
});
like image 664
developer747 Avatar asked Jan 30 '26 12:01

developer747


1 Answers

I think you are using Ext JS 5 or above version so use this.

Ext.app.ViewController instead of Ext.app.Controller.

like image 156
Mohit Saxena Avatar answered Feb 01 '26 00:02

Mohit Saxena



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!