angular.js - Using requireJS to manage JS, does angularJS no longer need to use ng-app?
PHPz
PHPz 2017-05-15 17:00:05
0
2
553

If you use requireJS to manage JS, doesn’t angularJS need to use ng-app as the entry point?
Can you explain it in detail? Thank you very much!

My brother solved it: http://www.open-open.com/lib/view/open14...

PHPz
PHPz

学习是最好的投资!

reply all(2)
曾经蜡笔没有小新

Since require.js is loaded asynchronously instead of blocking, when using require.js to load angular, if ng-app is defined in html, such a situation can easily occur.

So we cannot directly use ng-app to define angular modules

  • The solution is as follows:

define([ 'angular' , 'angular-ui-router' ] , function( angular ){

    window.name = 'NG_DEFER_BOOTSTRAP';
    var isloaded = false;

    var timer = setInterval(function(){
        angular.element(document).ready(function(){
            angular.bootstrap(document,["My_app"]);
            isloaded = true;
        });

        if(isloaded === true){
            clearInterval(timer);
        }
    },300);

    return angular.module('My_app',['ui.router']);
});
漂亮男人

I feel that gulp is better, requirejs is a little troublesome, and I have to write extra code for each js file, which I don’t like.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template