javascriptionic-frameworkonsen-uionsen-ui2

OnsenUI : uncaught ReferenceError: setImmediate is not defined


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>');


                    });

Solution

  • I solved adding this to the header tag

    <script>
         window.setImmediate = window.setTimeout;
    </script>