Angular + Requirejs - Loading in the wrong order

前端 未结 3 1942
旧时难觅i
旧时难觅i 2021-01-15 00:51

I\'m trying to have angular and jquery loaded with requirejs. The best I can do is that 50% of the time everything loads correctly, the other half I get the error No

3条回答
  •  醉话见心
    2021-01-15 01:25

    This might be a late response but as Dustin Blake said, you can also use jQuery .ready() instead of including another module like domReady.

    requirejs.config({
        paths: {
            jquery: '/path/to/jquery',
            angular: 'path/to/angular'
        }, shim: {
            angular: {
                exports: 'angular'
            },  
        }   
    });
    
    require(['jquery'], function($) {
        $(document).ready(function(){
            // I like it this way instead of including 
            // everything in the parent function so it's easier to read
            require(['angular', "modules/mainApp"], function(){
             angular.bootstrap(document, ['mainApp']);
            })
        })
    });
    

提交回复
热议问题