angular.js - 使用requireJS管理JS, angularJS就不需要用ng-app了吗?
PHPz
PHPz 2017-05-15 17:00:05
0
2
530

使用requireJS管理JS, angularJS就不需要用ng-app作为入口了吗?
能详细解释下吗,不胜感激!

小弟解决了: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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!