function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Kakasaheb EKKakasaheb EK 

Can I call JScontroller method from doInit in Lightning?

({
    doInit : function(component, event, helper) {
        helper.LoadAccount(component, event);
        helper.LoadApexAttribute(component, event);
        testmethodTest();
    },
    
    testmethodTest : function() {
        var action = component.get('c.myContact');
        action.setCallback(this, function(response) { 
            console.log('1111------');
            var state = response.getState();
            console.log('1111------'+state);
            if (state === "SUCCESS") {
                console.log('Test-' + JSON.stringify(response.getReturnValue()));
                component.set('v.MYContcat', response.getReturnValue());
            }
        });
        $A.enqueueAction(action);
    },
    
})

 
Kakasaheb EKKakasaheb EK
User-added image

Not able to call testmethodTest method?

 
Raj VakatiRaj Vakati
you need to call like this 
 
({
    doInit : function(component, event, helper) {
        helper.LoadAccount(component, event);
        helper.LoadApexAttribute(component, event);
        this.testmethodTest();
    },
    
    testmethodTest : function() {
        var action = component.get('c.myContact');
        action.setCallback(this, function(response) { 
            console.log('1111------');
            var state = response.getState();
            console.log('1111------'+state);
            if (state === "SUCCESS") {
                console.log('Test-' + JSON.stringify(response.getReturnValue()));
                component.set('v.MYContcat', response.getReturnValue());
            }
        });
        $A.enqueueAction(action);
    },
    
})