3

Onsen UI throwing error while dynamically rendering the onsen's js and css. But It's working when i using it in static htmls. Error: Uncaught ReferenceError: setImmediate is not defined

    internal.js:52 Uncaught ReferenceError: setImmediate is not defined
        at Object.internal$1.waitDOMContentLoaded (internal.js:52)
        at internal.js:103
        at onsElements (onsenui.js:6)
        at onsenui.js:7

My code.,

jsResource = ['https://cdnjs.cloudflare.com/ajax/libs/onsen/2.10.4/js/onsenui.js'];

    async.mapSeries(jsResource, function (file, callback3) {
                        // console.log('Enter FILE =>',file)
                        if (file) {
                            var jsFile = iframedocument.createElement('script');
                            jsFile.setAttribute('type', 'text/javascript');
                            jsFile.setAttribute('src', file);
                            head.appendChild(jsFile);

                            if (jsFile.readyState) {  //IE
                                jsFile.onreadystatechange = function () {
                                    if (s.readyState == "loaded" ||
                                        s.readyState == "complete") {
                                        s.onreadystatechange = null;
                                        callback3(null, null);
                                    } else {
                                        callback3(null, null);
                                    }
                                };
                            } else {  //Others
                                jsFile.onload = function () {
                                    callback3(null, null);
                                };
                            }

                        }
                        else {
                            callback3(null, null);
                        }
                    }, function (err, result) {
                        body.append('<script>' + resultData + '</script><script>' + jsCode + '</script>');


                    });
Saravanan S
  • 123
  • 1
  • 13
  • Did you ever find a solution for this? Happens with us on Angular production builds (though not in debug) – Marchy Jul 26 '19 at 18:57

1 Answers1

10

I solved adding this to the header tag

<script>
     window.setImmediate = window.setTimeout;
</script>
Michael Enitan
  • 512
  • 6
  • 10
DanielMescoloto
  • 180
  • 3
  • 16