1

I am getting error when I am calling modal like this

setTimeout(function() { $('#site-pop-up').modal('show'); }, 2000);

Error in console:

Uncaught Error: cannot call methods on modal prior to initialization; attempted to call method 'show'

Anyone have solution for this?

Thanks

  • how did you solved ? i am also getting same error – sumeet bajaj May 8 at 8:16
  • @sumeet Please share your code – Shiwani May 8 at 9:46
0

Add your code in require so that it will execute with jquery and modal is ready

require([
    'jquery',
    'Magento_Ui/js/modal/modal'
], function($){
    setTimeout(function() {
        jQuery('#site-pop-up').modal('show');
    }, 2000);
});
  • 1
    Thanks for the reply. This is working for me . I have defined in my requirejs-config.js like this "shim": { 'bootstrap': { 'deps': ['jquery','jquery/ui','Magento_Ui/js/modal/modal'] }, 'jquery-storageapi': { 'deps': ['jquery'] }, – Shiwani Apr 11 at 9:48
  • 1
    That's great, welcome :) +1 for the appreciation – Shoaib Munir Apr 11 at 9:51
  • @ShoaibMunir not working for me – sumeet bajaj May 8 at 8:16
  • Can you please share your code? – Shiwani May 8 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.