search

Home  >  Q&A  >  body text

angular.js - webpack require.ensure asynchronous loading of angular module problem

An error is reported when hot loading the login.controller.js below,

If you remove resolve and import './login.controller' directly at the top, no error will be reported. What is the reason for this?

#login.route.js 文件require.ensure打包加载
import LoginTpl from './login.tpl.html';

var LoginRoute = {
    template    :   LoginTpl,
    controller  :   'LoginCtrl',
    resolve: {
        loadModule : ['$q','$ocLazyLoad',function ($q,$ocLazyLoad) {
            return $q((resolve) => {
                require.ensure([], () => {
                    let module = require('./login.controller');
                    $ocLazyLoad.load({name: 'cm.bg.login'});
                    resolve(module);
                });
            });
        }]
    }
};
export default LoginRoute;

#login.controller.js 热加载的模块

import './login.module'
import '../../../service/LoginService' //登入服务

export default angular.module('cm.bg.login')
    .controller('LoginCtrl',['Login',function(LoginService){
                
    }])
    

Is it related to the order in which they are packaged? Packaged out, 104 is the loginService and 103 is under the contorller. If so, how to change it?

过去多啦不再A梦过去多啦不再A梦2840 days ago709

reply all(1)I'll reply

  • 天蓬老师

    天蓬老师2017-05-15 17:00:48

    Try webpack’s plugin : order occurrence

    reply
    0
  • Cancelreply