1

I have a property in my controller which I need to change its value in one method and access the updated value in another function. How can I do this?

Ext.define('App.controller.MyController', {
    extend: 'Ext.app.Controller',
     config:{
        Var : 'Test',
        },
    method1:function(){
        var me = this;
        var str1 = me.getVar();
        //change str1 here to Test2
    },
    method2:function(){
        var me = this;
        var str2 = me.getVar();
        //get updated value here (Test2)
    }

1 Answer 1

2

As your property is defined via config, getter and setter methods are already generated automatically, i.e. in method1 you can just call the setter to change the value:

method1: function() {
    var me = this;
    me.setVar('Test2');
},

Also refer to the documentation, as this very basic case is covered there.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.