[AngularJS] ocLazyLoad -- Lazy loaded module should contain all the dependencies code

Recentlly works with AngularJS + ocLazyLoad, our project have break down into multi small modules. For example

mainApp module

| -- vendor module

| -- child 1 module

| -- child 2 module

| -- ....

'vendor, child1, child2' they are spreated npm modules.

'vendor' contains all the common used libs. Because we have multi AngularJS projects on going, vendor module is shared among all of them.

One problem I met when apply lazy loaded is that, for example, I want to lazy load Child1 module, any child 1 module contains a lib call angular-scroll which locates in vendor module. And mainApp Module doesn't use angular-scroll lib.

angular.module('Child1', ['duScroll'])

When I lazy load Child1, it reports error that:

'duScroll'Provider' is not found

Because Child1 doesn't have this lib included, this lib was included in vendor module, ocLazyLoad requires:

lazy loaded modules should contains all the dependencies code, unless the dependencies was already declare in main app module

So the solution to solve the problem is include 'duScroll' into mainApp module:

angular.module('mainApp', ['duScroll'])
上一篇:webpack.config.js配置遇到Error: Cannot find module '@babel/core'&&Cannot find module '@babel/plugin-transform-react-jsx' 问题


下一篇:windows 与 mac socket通信