0

I try to added HTML + RequireJS to DIV tag via ajax loading.

With content contain tags like <script type="text/x-magento-init"> or data-mage-init attribute, It's easy to bind event using $('#selector').trigger('contentUpdated'). In the case, it can be re-initialize on mage/apply/main using function:

    function init(el, config, component) {
      require([component], function (fn) {

        if (typeof fn === 'object') {
            fn = fn[component].bind(fn);
        }

        if (_.isFunction(fn)) {
            fn(config, el);
        } else if ($(el)[component]) {
            $(el)[component](config);
        }
      });
   }

And I know we can be switch <script> require(...)</script> on append HTML to <script type="text/x-magento-init">.

But I want to try another way to re-init requirejs. Any ideas for this issue?

2
  • 1
    Can you explain why you want to re-init require JS please? It sounds like a strange thing to want to do, or I'm not understanding the question.
    – Ben Crook
    Commented Jan 4, 2018 at 16:12
  • In some case, I want to re-used require js on content like <script type="text/x-magento-init"> and don't bind new event for it.
    – LinoPham
    Commented Jan 4, 2018 at 16:23

0