Yasitha Bandara
Yasitha Bandara

Reputation: 2395

Call function of a dynamically loaded instance of a es6 class

I'm trying to import "SampleModuleController" class dynamiclly using webpack and call its member function as follows.

sampleModule.js

  class SampleModuleController{
    
        getSampleModuleSheet()
        {
            console.log("getSampleModuleSheet");
        }
    
    }
    export let sampleModuleController = new SampleModuleController();

in a another class file...

async clicked(){
    const getView = await import('../../controllers/sampleModule');
    console.log("getView--",getView);
    getView.getSampleModuleSheet();
}

but it gives me following logs and errors

enter image description here

Upvotes: 0

Views: 158

Answers (1)

me.nkr
me.nkr

Reputation: 108

    async clicked() {
      const {sammpleModuleController: getView} = await import ('../../controllers/sampleModule');
      console.log("getView--", getView);
      getView.getSampleModuleSheet();
    }

Upvotes: 1

Related Questions