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

2
  • how did you solved ? i am also getting same error Commented May 8, 2019 at 8:16
  • @sumeet Please share your code
    – Shomita
    Commented May 8, 2019 at 9:46

1 Answer 1

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);
});
7
  • 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'] },
    – Shomita
    Commented Apr 11, 2019 at 9:48
  • 1
    That's great, welcome :) +1 for the appreciation Commented Apr 11, 2019 at 9:51
  • @ShoaibMunir not working for me Commented May 8, 2019 at 8:16
  • Can you please share your code?
    – Shomita
    Commented May 8, 2019 at 9:45
  • @Shiwani stackoverflow.com/questions/56021829/… Commented May 8, 2019 at 10:06

Your Answer

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

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