Magento 2 popup modal

 How to use magento 2 modal for popup.


There are tow ways to initiate popup modal in magento 2.

1) Using js.

require(

    [

     'jquery',

        'Magento_Ui/js/modal/modal'

    ],

    function(

        $,

        modal

    ) {

        var options = {

            type: 'popup',

            responsive: true,

            innerScroll: true,

            buttons: [{

                text: $.mage.__('Continue'),

                class: 'mymodal1',

                click: function () {

                    this.closeModal();

                }

            }]

        };


        var popup = modal(options, $('#popup-modal'));

        $("#click-me").on('click',function(){

            $("#popup-modal").modal("openModal");

        });

    }

); 

2) Binding in html using data-bind attribute of magneto.


<button type="button" class="action" data-trigger="trigger">
    <span data-bind="i18n: 'Open Popup'"></span>
</button>
<div data-bind="mageInit: {
        'Magento_Ui/js/modal/modal':{
            'type': 'popup',
            'title': 'I am Popup title',
            'trigger': '[data-trigger=trigger]',
            'responsive': true,
            'buttons': [{
                text: jQuery.mage.__('Submit'),
                class: 'action'
            }]
        }}">
    <div class="content">
        I am Popup Content
    </div>
</div>
  


Comments

Popular posts from this blog

Hosting and Goodies

Magento 2 Import Scripts

How to add product attribute value in minicart magento 2